August
22
How to use Powershell to Export All Distribution Groups and Members to CSV
Create a temp fold at c:\ called c:\temp and run the following script
$Groups = Get-DistributionGroup
$Groups | ForEach-Object {
$group = $_.Name
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
If($members) {
$members=$members + ";" + $_.Name
} Else {
$members=$_.Name
}
}
New-Object -TypeName PSObject -Property @{
GroupName = $group
Members = $members
}
} | Export-CSV "C:\temp\Distribution-Group-and-Members.csv" -NoTypeInformation -Encoding UTF8