Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

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"
    }
}
share|improve this answer
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 '10 at 15:53

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.

share|improve this answer

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)"
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.