2

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?

3 Answers 3

6

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"
    }
}
1
  • 1
    I 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)" } }
    – Rob Burke
    Jul 13, 2010 at 15:53
0

Or if you'd rather use the Powershell that comes with Exchange, here is an alternate script. It'll

 # dump all DLs to a variable, whether DistributionList or mail-enabled Sec-group
 $DLList = get-distributiongroup
 # Iterate over each DL to get member-list
 foreach ($DL in $DLList) {
     # Get the member list
     $Dmember=get-distributiongroupmember $DL
     # Get DL name
     $Dname=$DL.name
     # Start outputting
     write-output "`q$Dname`q" -nonewline
     # Iterate over member list, outputting
     foreach ($Member in $Dmember) {
         $MName=$Member.DisplayName
         write-output ",`q$MName`q" -nonewline
     }
     # Add terminal line-feed
     write-output "`n"
 }

This should produce output that looks like:

 "Accounting","Mary Joe","Fred Smith"
 "Receiving Office"
 "Office, home","John Birtram"

Adust however you need to.

This script came largely off the top of my head and probably contains bugs.

0

I've accepted Torai's answer as it was the one I used but I made a small change in the foreach look to have it output the Distribution List on the same line as the User data:

foreach ($objResult in $colResults){
    $objItem = $objResult.Properties;
    foreach ($objMember in $objItem.member) {
        Write-Output "$($objItem.cn),$($objMember)"
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .