#Requires -Version 3.0 param([string]$User) ## Install ExchangeOnlineManagement module if it doesn't already exist If ( !(Get-Module -ListAvailable -Name ExchangeOnlineManagement) ) { Try { Install-Module -Name ExchangeOnlineManagement -RequiredVersion 1.0.1 } Catch { Write-Output $_.Exception.Message ; Exit } } Import-Module ExchangeOnlineManagement Connect-ExchangeOnline -UserPrincipalName $User -ShowProgress $true $Groups = Get-UnifiedGroup -ResultSize Unlimited $Groups | ForEach-Object { $group = Get-UnifiedGroupLinks -Identity $_.Name -LinkType Members -ResultSize Unlimited $group | ForEach-Object { New-Object -TypeName PSObject -Property @{ Group = $group.DisplayName Member = $_.Name EmailAddress = $_.PrimarySMTPAddress RecipientType= $_.RecipientType } } } | Export-CSV “${Env:UserProfile}\Desktop\group-export.csv" -NoTypeInformation -Encoding UTF8 Disconnect-ExchangeOnline