How to Add Members to Office 365 Group using PowerShell?

Requirement: Add members to the Office 365 group using PowerShell.

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

Microsoft 365 groups help you collaborate and share information with colleagues, clients, or customers. This post will show you how to add a member to a Microsoft 365 group using the Microsoft Admin Center. Also, we will show you how to add a member to an Office 365 group by using PowerShell. Let’s get started!

You can add members to any Office 365 group through Microsoft 365 admin center as an admin. Here is how:

  1. Log in to the Microsoft 365 Admin Center site as global admin: https://admin.microsoft.com
  2. Expand “Teams & Groups” and Click on “Active Teams & Groups” in the left navigation.
  3. Select the Office 365 group you wish to add member(s) to.
  4. Click on the “Members” tab and select Members and then click on “Add members”.
    add members to office 365 group powershell
  5. Search and select members to add, and then click on the “Add” button at the bottom. When you’re finished adding members, select Close.

That’s all! The new member will appear in the Members list for the group. By adding members to your group, you can give them access to the resources and information that they need to be productive.

How to Add Users to Office 365 Group using PowerShell?

To add a group member, You’ll need the group’s ID and the email address of the person you want to add as a member. Let’s add “John@TheCrescentTech.com” to the “Accounts@TheCrescentTech.com” Office 365 group using the Exchange Online Management PowerShell cmdlet Add-UnifiedGroupLinks.

#Get Credentials to connect
$Credential = Get-Credential
 
#Connect to Exchange Online
Connect-ExchangeOnline -Credential $Credential -ShowBanner:$False

#PowerShell to add a user to office 365 group
Add-UnifiedGroupLinks -Identity "Accounts@TheCrescentTech.com" -LinkType "Members" -Links "john@TheCrescentTech.com"

#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False

Bulk Add Members to Office 365 Group using PowerShell

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

Add-UnifiedGroupLinks -Identity "Accounts@TheCrescentTech.com" -LinkType "Members" -Links "john@TheCrescentTech.com","peter@TheCrescentTech.com" 

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 = "Steve@crescent.com"

#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False

#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

PnP PowerShell to Add a Member to Microsoft 365 Group

Use this PnP PowerShell script to add a member to a Microsoft 365 group:

#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$GroupEmail = "HRAdmin@crescent.com"
$MemberEmail = "Steve@crescent.onmicrosoft.com"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $AdminSiteURL -Interactive

    #Get the Office 365 Group from Email
    $Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail

    #Get Members of the group
    $GroupMembers = Get-PnPMicrosoft365GroupMembers -Identity $Group | Select -ExpandProperty UserPrincipalName

    #Check if group exists
    If($Group -ne $Null)
    {
        #Check if the given user is already a Member of the group
        If($GroupMembers -notcontains $MemberEmail)
        {
            #Add Member to the Group
            Add-PnPMicrosoft365GroupMember -Identity $Group -Users $MemberEmail
            Write-Host "Group Member Added Successfully!" -f Green
        }
        Else
        {
            Write-Host "User is already in the Group Members List!" -f Yellow
        }
    }
    Else
    {
        Write-host "Could not Find Group!" -f Yellow
    }
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

PnP PowerShell to Add Users to SharePoint Online Site’s Associated Members Group

This time, let’s add the user to the associated Microsoft 365 Group member using the PnP PowerShell cmdlet Add-PnPMicrosoft365GroupMember:

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/CorporateBranding"
$SiteOwner= "Steve@crescent.com"
 
Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
 
    #Get the Site
    $Site = Get-PnPSite -Includes GroupId
      
    #Add user to the Site's associated Microsoft 365 Group Member
    Add-PnPMicrosoft365GroupMember -Identity $Site.GroupId -Users $SiteOwner
    Write-host "Added Member to the Associated Microsoft 365 Group!" -f Green    
}
Catch {
    Write-host -f Red "Error:" $_.Exception.Message
}

Let’s see how to add bulk users to the group using PowerShell in Office 365.

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
 
#Connect to Exchange Online
Connect-ExchangeOnline -Credential $Credential -ShowBanner:$False

#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)'"
}

#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False

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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

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

  • Hello, Thanks for your work on this. On the CSV bulk group import I had to add a pipe | before the write-host on the below command.
    Import-CSV “C:\temp\NYLAYSS.csv” | ForEach-Object {Add-UnifiedGroupLinks -Identity $_.GroupID -LinkType Members -Links $_.Member | Write-host -f Green “Added Member ‘$($_.Member)’ to Office 365 Group ‘$($_.GroupID)'”}

    I received an error A positional parameter cannot be found that accepts the argument ‘Write-host’ without it.

    Reply
  • I’m running into a problem with this, and I am not sure if this is where to turn, but because Microsoft’s naming scheme for services has become increasingly confusing, googling for help hasn’t been much use, nor has Microsoft’s documentation.

    With the help of this blog I have been able to run a script that will add users to my Office365 group, but only if they are internal users or existing contacts.

    I am trying to bulk add about 120 guest users to an Office365 group without them having to click an invitation (they’re already on a listserv but the server died; long story).

    The problem I am running into is that apparently they have to already exist as guest users in the Azure AD tenant.

    Is there a way to bulk add guests to the tenant without them needing to accept the invitation/click on something first?

    Reply
  • Is there a way to suppress notification email when you add?

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

    Thank You!

    Reply
  • 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 ‘group1@testing.com’.

    Please help.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *