Ever needed to quickly pull a list of members from your Microsoft 365 Groups and export them? In this quick post, I’ll share a simple PowerShell script using the Get-UnifiedGroup cmdlet that does exactly that — filters your groups and dumps all members into a tidy CSV file.
The PowerShell Script
Use the Get-UnifiedGroup CMDLet and if your sites are prefixed like mine, filter on the DisplayName.
$CSVPath = "C:\Temp\AllGroupMembers.csv"
Connect-ExchangeOnline
$list=Get-UnifiedGroup -Filter "DisplayName -like 'SitePrefix*'"
foreach ($Group in $list)
{
#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
}
Output
The above script will return a CSV.
| Group Name | User Name | PrimarySmtpAddress |
Output from CSV