PowerShell Get List of Members from O365

Quite a short post really. Have you ever needed or wanted to get a list of members for an O365 Group? Then I have a simple PowerShell for that. 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
}

The above script will return a CSV.

Group NameUser NamePrimarySmtpAddress
Output from CSV

Share