Get report on number of users in each DDL (dynamic distribution group)

This script gets the number of users in each DDL, it does not provide the list of the users.


Write-Host "Getting All The DDLs" -ForegroundColor Cyan
$Report="DDL-Report.csv"
$DDLs = Get-DynamicDistributionGroup -ResultSize Unlimited

$primaryCounter=0 
$data=@()

Foreach ($DDL in $DDLs)
{
 $primaryCounter++
 Write-Progress -Activity "Processing Groups" -Status "Current Group: $($DDL.Name) ($($primaryCounter)/$($DDLs.Count))" `
 -Id 1 -PercentComplete (($primaryCounter/$DDLs.Count)*100)
 Write-Host "Finding Number of users that are currently members of $($DDL.Name)"
    $entry = $ddl | select Name, AcceptMessagesOnlyFrom, ManagedBy,
    AcceptMessagesOnlyFromDLMembers, AcceptMessagesOnlyFromSendersOrMembers, BypassModerationFromSendersOrMembers,
    ModeratedBy, ModerationEnabled, RejectMessagesFrom, RejectMessagesFromDLMembers, 
    RejectMessagesFromSendersOrMembers, RequireSenderAuthenticationEnabled, @{
    n="MemberCount";e={(Get-Recipient -RecipientPreviewFilter $DDL.RecipientFilter -ResultSize Unlimited).count}}
    $data+= $entry
}
$data | Export-CSV $Report -notype

Below version of script is for the Exchange Server Environment.

Comments