How to Get Office 365 Group Members using PowerShell?

Requirement: Get Members of Office 365 Group using PowerShell

How to Get Office 365 Group Members?

To get a list of members in Office 365 group from Microsoft 365 admin center,

  • Log in to the Microsoft 365 Admin Center site: https://admin.microsoft.com
  • Expand Groups and Click on the Groups link in the left navigation. 
  • The group’s page lists all groups in your Office 365 tenant. Pick the desired group to list users in the group.
  • This opens the group’s details page which lists group members
    get members of office 365 group powershell

PowerShell to Get Group Members in Office 365:

Here is the Office 365 PowerShell get group members

#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

#Get all Members of Office 365 Group
Get-UnifiedGroup -Identity "[email protected]" | Get-UnifiedGroupLinks -LinkType Member
 
#Remove the session 
Remove-PSSession $Session 

You can export Office 365 group members using PowerShell as:

#Get all Members of Office 365 Group and export to CSV
Get-UnifiedGroup -Identity "[email protected]h.com" | Get-UnifiedGroupLinks -LinkType Member `
      | Select DisplayName,PrimarySmtpAddress | Export-CSV "C:\Temp\GroupMembers.csv" -NoTypeInformation

Export Office 365 Group Members to CSV using PowerShell

Let’s export all members of all Office 365 groups 

$CSVPath = "C:\Temp\AllGroupMembers.csv"

#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

#Remove the CSV file if exists
If(Test-Path $CSVPath) { Remove-Item $CSVPath}

#Get All Office 365 Groups
$O365Groups=Get-UnifiedGroup
ForEach ($Group in $O365Groups) 
{ 
    Write-Host "Group Name:" $Group.DisplayName -ForegroundColor Green
    Get-UnifiedGroupLinks -Identity $Group.Id -LinkType Members | Select DisplayName,PrimarySmtpAddress

    #Get Group Members and export to CSV
    Get-UnifiedGroupLinks -Identity $Group.Id -LinkType Members | Select-Object @{Name="Group Name";Expression={$Group.DisplayName}},`
         @{Name="User Name";Expression={$_.DisplayName}}, PrimarySmtpAddress | Export-CSV $CSVPath -NoTypeInformation -Append
}
 
#Remove the session 
Remove-PSSession $Session

Get Office 365 Group Members using Azure AD PowerShell Module

You can also list group users using Azure AD PowerShell as:

#Get Credentials to connect
$Cred = Get-Credential

#Connect to AzureAD
Connect-AzureAD -Credential $Cred

#Get the Group
$Group = Get-AzureADGroup -Filter "DisplayName eq 'HR Team'"

#Get Group Members
Get-AzureADGroupMember -ObjectId $Group.ObjectId

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!

12 thoughts on “How to Get Office 365 Group Members using PowerShell?

  • March 10, 2021 at 1:00 PM

    Same error here: “”A positional parameter cannot be found that accepts argument ‘Members’.” It’s something to do with the For loop. If you just run

    Get-UnifiedGroupLinks “Identity GroupName “LinkType Members | Select DisplayName,PrimarySmtpAddress

    it works fine.

    Reply
  • June 30, 2020 at 4:56 PM

    What about if I wish to export users who are assigned with Office E1 SKU ID: StandardPack

    Reply
  • March 17, 2020 at 1:27 PM

    Thank You for Share your experience!

    Reply
  • March 2, 2020 at 4:49 AM

    do you have any suggestions if PS timeouts due to MFA .. am getting incomplete output.

    Reply
    • March 2, 2020 at 3:04 PM

      Remove the -Credential parameter! Then you’ll be prompted to enter credentials in a popup window, which is MFA aware! So, instead of “Connect-AzureAD -Credential $Cred”, just use: Connect-AzureAD

      Reply
  • July 25, 2019 at 10:22 PM

    “A positional parameter cannot be found that accepts argument ‘Members’.” on each site when trying to create the CSV.

    Reply
    • October 26, 2020 at 9:39 PM

      I’m getting the same issue. Did you find a resolution?

      Reply
    • October 26, 2020 at 10:17 PM

      I believe that it is just a typo. I think it should be Member not Members

      Reply
      • August 10, 2021 at 3:02 AM

        Did you try it? That’s not the issue. Official documentation has Members.

        Reply
    • August 10, 2021 at 3:07 AM

      The other comments are wrong. The problem is they hyphens in front of LinkType and also Identity. They’re not real hyphens. remove them and replace them with real hyphens.

      Reply
      • August 31, 2021 at 7:06 PM

        thank you! I was slamming my head against a wall on that

        Reply
  • April 9, 2019 at 6:08 AM

    Your blog has been a tremendous resource for us!

    Reply

Leave a Reply