The following PowerShell commands will help you generate a list of distribution groups that have received mail in the last 30 days. The second command pulls data from the Exchange Tracking Logs which only keep 30 days worth of data by default.
Get all distribution lists:
1
|
Get-DistributionGroup | Select-Object PrimarySMTPAddress | Sort-Object PrimarySMTPAddress | Export-CSV DL-ALL.csv -notype
|
Get all distribution lists used over last 30 days:
1
|
Get-MessageTrackingLog -Server -EventId Expand -ResultSize Unlimited |Sort-Object RelatedRecipientAddress | Group-Object RelatedRecipientAddress |Sort-Object Name | Select-Object @{label=”PrimarySmtpAddress”;expression={$_.Name}}, Count | Export-CSV DL-Active.csv -notype
|
Compare preview two files and present list of inactive:
1
2
3
|
$file1 = Import-CSV -Path “DL-ALL.csv”
$file2 = Import-CSV -Path “DL-Active.csv”
Compare-Object $file1 $file2 -Property PrimarySmtpAddress -SyncWindow 500 |Sort-Object PrimarySmtpAddress | Select-Object -Property PrimarySmtpAddress |Export-Csv DL-Inactive.csv -NoType
|