A script to list DLs that has MailUniversalDistributionGroup as member

The script gives list of DLs that has MailUniversalDistributionGroup as member. The script is NOT intended to give nested groups. The output of the script will give only DL name that has MailUnitversalDistributionGroup as member and count of member MailUniversalDistributionGroup. The count does not include DDL.

 

Output looks as ,

The Script :

 $memGrpCnt=0 

$grplst=get-distributiongroup -ResultSize unlimited   

$grplst | foreach-object {     

$curgrpmplt++  

$curgrp=$_    

$grplstls=$curgrp.alias 

$dn= $curgrp.displayname 

write-progress -activity "Checking the DL to calculate " -status "Currently processing the DL(alias) :     $grplstls" -percentcomplete (($curgrpmplt/$grplst.count)*100)   $memGrpCnt=@(get-distributiongroupmember $curgrp.alias | where{$_.recipienttype -eq "MailUniversalDistributionGroup"}).count   

if ($memGrpCnt -gt 0)  { 

write-host $dn,$memGrpCnt  "$dn,$memGrpCnt" | out-file -filepath C:\test\DLwithGrp.txt -append  $memGrpCnt=0 

else  {  $memGrpCnt=0  } 

 What the script does,

- It takes all the DLs and stores in $grplst.

- Then gets into foreach loop to check each DL membership.

- As it is required to give progress percentage , additional variables like $curgrpmplt,$grplstls created.

- It uses get-distributiongroupmember command to count the group member.

- If DL has a group as member, then it prints DL Name and count on the screen, then writes to a file.

Requirement,

- The script is to be executed from Exchange Management Shell

- The output is stored to a file. So you need to modify the location of the file  in the script ie. "c:\test\DLwithGrp.txt" should be changed to existing path.

Download:

You can download the script from : https://gallery.technet.microsoft.com/office/A-script-to-list-DLs-that-2b0497a0