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.
- The name of the DL.
- Type of DL (Static or Dynamic)
- Number of members.
- Display Name of members.
- 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
}