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?

Office 365 Groups offer a convenient way to collaborate with other people in the organization. If you need to get a list of all the group members, PowerShell makes it easy. This guide will show you how to use PowerShell to get the list of users in an Office 365 Group. Let’s get started!

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

  • Log in to the Microsoft 365 Admin Center site:
  • 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 with Get-UnifiedGroup and Get-UnifiedGroupLinks cmdlets.

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

#Get all Members of Office 365 Group
Get-UnifiedGroup -Identity "[email protected]" | Get-UnifiedGroupLinks -LinkType Member
#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False

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]" | Get-UnifiedGroupLinks -LinkType Member `
      | Select DisplayName,PrimarySmtpAddress | Export-CSV "C:\Temp\GroupMembers.csv" -NoTypeInformation

Export Office 365 Group Members to CSV using PowerShell

Ever needed to get a list of all the members in a Microsoft 365 group and export them to a CSV file? Sure, We can use PowerShell to quickly retrieve a list of all the members in groups. Here is the PowerShell to export all members of all Office 365 groups:

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

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

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

#Get All Office 365 Groups
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
#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False

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 - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

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

  • Thank you for this. Can is be easily scoped to list all groups a single user is a member of?

  • 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.

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

  • Thank You for Share your experience!

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

    • 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

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

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

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

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

    • 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.

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

  • Your blog has been a tremendous resource for us!


Leave a Reply

Your email address will not be published.