Powershell Script to report on Exchange 2010 Distribution Lists

This powershell script allows you to create a report for a bunch of distribution lists that match a certain criteria. In an example here, if you want to search your entire exchange organization for all DLs (static and dynamic) that contain the word “sales”, the script would return the following information.

  1. The name of the DL.
  2. Type of DL (Static or Dynamic)
  3. Number of members.
  4. Display Name of members.
  5. Title of members.

Here’s the script:

$searchterm = "sales"

$DistListSearch = Get-DistributionGroup | where-object { $_.DisplayName -like "*$searchterm*" }
$DistListSearch | foreach {
	$DistGrp = $_
	$DistGrpCount = (Get-DistributionGroup $DistGrp | Get-DistributionGroupMember).count
	"$DistGrp - Total Members = $DistGrpCount - Static Distribution List"
	Get-DistributionGroup $DistGrp | Get-DistributionGroupMember | ft Name, Title
	}

$DynDistListSearch = Get-DynamicDistributionGroup | where-object { $_.DisplayName -like "*$searchterm*" }
$DynDistListSearch | foreach {
	$DynDistGrp = $_
	$DynDistGrpCount = (Get-Recipient -RecipientPreviewFilter $(Get-DynamicDistributionGroup -Identity $DynDistGrp).RecipientFilter -ResultSize Unlimited).count
	"$DynDistGrp - Total Members = $DynDistGrpCount - Dynamic Distribution List"
	Get-Recipient -RecipientPreviewFilter $(Get-DynamicDistributionGroup $DynDistGrp -ResultSize Unlimited).RecipientFilter | ft Name, Title
	}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>