-->

Saturday, June 16, 2018

Exchange - Get Distribution Groups That Contain Mail Contacts

A lot of organizations, including mine, add external contacts to Distribution Groups. In my case, we have a US and EU business units and users need to be included in groups. A lot of administrative housekeeping involves reporting which of those groups contain contacts.

There's no easy oneliner or a way to grab all the groups at once in the EAC or ADUC to get that info, so I threw together a quick little script that will list those DL's for us.

You can grab the script from my Google Drive here

-or-

Copy the following block into Notepad and save it as something like Get-DL-Contacts.ps1

foreach($dl in get-group -resultsize unlimited )
 {
  foreach ($member in $dl.members)
  {
   $recipient = ($member | get-recipient -erroraction silentlycontinue)
   if ($recipient.RecipientType -eq "MailContact")
   {
    Write-Host "$($dl.Name) Contains Contacts"
    break
   }
  }
 }


Once you have the .ps1 file, fire up the Exchange Management Shell, cd to the location you saved it and run Get-DL-Contacts.ps1

**Note** If you need to report on Mail Users instead of Contacts, change the $recipient.RecipientType -eq "MailContact") to $recipient.RecipientType -eq "MailUser")

Depending on the amount of distros you have, it might take a while to run (I have 1500 and it took about 30 minutes) but when it completes, you'll get the list of lists in the PS window.

**Note** When I have time I'll update the script to list both the DL's and the actual contacts within each one...unless one of my readers wants to do that for me :)

No comments:

Post a Comment