How to Add Members to Office 365 Group using PowerShell?

Requirement: Add members to office 365 group using PowerShell

How to add users to Office 365 Group using Admin Center?

As an admin, you can add members to any Office 365 group through Microsoft 365 admin center. Here is how:

  • Login to the Microsoft 365 Admin Center site: https://admin.microsoft.com
  • Expand Groups and Click on the Groups link in the left navigation. 
  • Select the Office 365 group you wish to add members
  • Click on the Edit link next to the Members column in the details pane.
    add user to office 365 group using powershell
  • On the Group page, Click on Add Members button >> Search and select users you wish to add to the group. You can find and add multiple users in a single stretch.
    how to add users to office 365 group powershell
  • Click on “Save” once you are done! You’ll see “Group membership was updated and will take effect immediately.” message.

How to Add Users to Office 365 Group using PowerShell?

Let’s add “[email protected]” to “[email protected]” Office 365 group using PowerShell.

#Get Credentials to connect
$Credential = Get-Credential
 
#Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
           -Credential $Credential -Authentication Basic -AllowRedirection
 
#Import the session
Import-PSSession $Session -DisableNameChecking

#PowerShell to add a user to office 365 group
Add-UnifiedGroupLinks -Identity "[email protected]" -LinkType "Members" -Links "[email protected]"

#Remove the session
Remove-PSSession $Session 

Bulk Add Members to Office 365 Group using PowerShell

Likewise, you can add multiple users comma separated. E.g.

Add-UnifiedGroupLinks -Identity "[email protected]" -LinkType "Members" -Links "[email protected]","[email protected]"
 

Add Group Member to SharePoint Online Site:

Here is how to add a group member to the associated group of a given SharePoint Online site.

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Legal"
$UserID = "[email protected]"

#Establish Exchange Session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
    -Credential (Get-Credential) -Authentication Basic -AllowRedirection
Import-PSSession $Session

#Get the Office 365 group of the SharePoint site
$Group = Get-UnifiedGroup -ResultSize Unlimited | Where { $_.SharePointSiteUrl -eq $SiteURL}

#Add Group Member
Add-UnifiedGroupLinks -Identity $Group.DistinguishedName -LinkType Members -Links $UserID

PowerShell to Add Users to Office 365 Group from CSV

Here is how to bulk add members to Office 365 group from a CSV file using PowerShell:

PowerShell to Add Users to Office 365 Group from CSV

Import Office 365 Group members from CSV File:

#Get Credentials to connect
$Credential = Get-Credential
 
#Create the session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
           -Credential $Credential -Authentication Basic -AllowRedirection
 
#Import the session
Import-PSSession $Session -DisableNameChecking

#PowerShell to Import Members to office 365 group from CSV
Import-CSV "C:\Temp\GroupMembers.csv" | ForEach-Object {
    Add-UnifiedGroupLinks -Identity $_.GroupID -LinkType Members -Links $_.Member
    Write-host -f Green "Added Member '$($_.Member)' to Office 365 Group '$($_.GroupID)'"
}

#Remove the session
Remove-PSSession $Session

To Add owner to Office 365 group, use: How to Add Owner to Office 365 Group using PowerShell?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “How to Add Members to Office 365 Group using PowerShell?

  • June 7, 2021 at 5:14 PM

    Thanks for the article. Very helpful.
    Can you please help on how I can add a user to multiple O365 groups?

    Thank You!

    Reply
  • May 13, 2021 at 2:18 AM

    I am following your guide “Import Office 365 Group members from CSV File”,
    But it’s giving me the following error;

    Add-UnifiedGroupLinks: A positional parameter cannot be found that accepts argument ‘[email protected]’.

    Please help.

    Reply

Leave a Reply