PowerShell: Generate a list of all Office 365 Groups with members
- Tomas Bjerved
- Sep 19, 2022
- 1 min read
When doing migration projects between Office 365 tenants, you might need to make som lists of all the groups in a Office 365 tenant and include all the members of these groups. The easiest way to do this is with some Powershell magic. I have another article about connecting your Powershell to the Office 365 tenant, so I will not put that code in here. Here you will find the code to generate a CSV file with all the needed information:
$OutputFile = “o365GroupMembers.csv” $arrDLMembers = @{} $objDistributionGroups = Get-UnifiedGroup -ResultSize Unlimited
Foreach ($objDistributionGroup in $objDistributionGroups) { $objDGMembers = Get-UnifiedGroupLinks -Identity $($objDistributionGroup.PrimarySmtpAddress) -LinkType members
Foreach ($objMember in $objDGMembers)
{ Out-File -FilePath $OutputFile -InputObject “$($objDistributionGroup.DisplayName), $($objDistributionGroup.PrimarySMTPAddress), $($objMember.DisplayName), $($objMember.PrimarySMTPAddress), $($objMember.RecipientType)” -Encoding UTF8 -append } }
Commentaires