Powershell to list Distribution Lists and users contained within
I have recently been working on a project that required me to provide an extensive list of distribution groups and all users within that list. Obviously something that i did not want to do manually as it would have taken a massive amount of time. So I created some powershell to do it for me
The script is as follows
1 2 3 4 5 6 7 8 9 10 11 12 |
$saveto = "C:\\listmembers.txt" Get-DistributionGroup | sort name | ForEach-Object { "`r`n$($_.Name)`r`n=============" | Add-Content $saveto Get-DistributionGroupMember $_ | sort Name | ForEach-Object { If($_.RecipientType -eq "UserMailbox") { $_.Name + " (" + $_.PrimarySMTPAddress + ")" | Add-Content $saveto } } } |