All Users in All DL’s

Last week I had a customer ask me to provide them with a list of all of the users in all of their Distribution lists (DL). When I first took this ticket I figured it would be a quick one liner in the Exchange Management Shell; That idea ended up being wrong. Took me a few hours to come up with an answer so I figured I better post the answer incase it can help out someone else. Below was my guess and the output.

My Guess at a one-liner
Get-DistributionGroup -OrganizationalUnit"rebob/bob" | Get-DistributionGroupMember | out-file dl.txt
The output – missing the DL – a list of users is not helpful to me
Name                                                                          RecipientType                        
—————                                                                ————-                         
f919e368-1878-4aa0-adf8-a83635cc3031                 MailContact                           
ee2ea8f6-5306-4d75-866d-33431d915d27               MailContact                

Working out who is in a group on a single group basis is simple. Working out who is in a group when you want a list of groups is a bit harder. The Get-DistributionGroup cmdlet does not pass the group name in a useable format to the Get-DistributionGroupMemeber command. Without the group name in the pipe, and with the group me membership property on a user object being a multivalue your output is simply a list of users and no relation to group. I had Hayes help me write something, but he ran short on time. I then asked the Sunbelt Exchange list for help and I got a sample script from Rob Campbell that worked smashingly. Below is the script Rob provided to me:

    $dl_recs = @()
    $groups = get-distributiongroup -organizationalunit "<OU>"
    foreach ($group in $groups){
        get-distributiongroupmember $group |% {
        $_ | Add-Member -MemberType NoteProperty -Name "DL" -Value $group.displayname
        $dl_recs += $_
    $dl_recs | select DL,Name,RecipientType | Export-Csv dl.csv -notype

NOTE | replace the <OU> with the customers OU in AD. for example “bob/miller/is/cool/"

For people running into the same question I hope this helps you answer the request.

Related Posts with Thumbnails

About Kevinm