PowerShell script used to recursively get a list of all members within a Distribution Group.
-
Execute the function code.
-
Call the function:
Get-DistributionGroupMemberRecursive -Group "GroupName" | Export-csv -Path C:\test.csv -Delimiter ',' -Encoding 'UTF8'
Here is how to setup the connection with Office 365 Exchange servers through Powershell:
Set-ExecutionPolicy RemoteSigned
$365Logon = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365Logon -Authentication Basic -AllowRedirection
If you have large Distribution Groups, make sure to ajust the ResultSize
parameter of Get-DistributionGroup
:
Get-DistributionGroup -ResultSize Unlimited
Thanks to Mike Goldwin for his original code.
Thanks to JScott for column header labels code.