How to get a list of all Distribution Lists and their Members in Exchange 2007?
21,776
Distribution groups are stored in Active Directory. This Powershell script will list all the distribution groups in the AD domain and their members. If you atually have them stored as security groups, remove "(|(groupType=2)(groupType=4)(groupType=8))".
$strFilter = "(&(objectCategory=Group)(|(groupType=2)(groupType=4)(groupType=8)))"
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$objSearcher.PropertiesToLoad.Add("cn") | Out-Null
$objSearcher.PropertiesToLoad.Add("member") | Out-Null
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults){
$objItem = $objResult.Properties;
Write-Output $objItem.cn
foreach ($objMember in $objItem.member) {
Write-Output " $objMember"
}
}
Related videos on Youtube
Author by
Peter Short
Updated on September 17, 2022Comments
-
Peter Short over 1 year
I'm looking to get a list of all Distribution Lists in Exchange along with their members? Is this possible using any built-in Exchange tools? Powershell? Third party tools?
-
Peter Short almost 14 yearsI made one small change to output the Distribution List on the same line as the user: foreach ($objResult in $colResults){ $objItem = $objResult.Properties; foreach ($objMember in $objItem.member) { Write-Output "$($objItem.cn),$($objMember)" } }