Determine if Exchange Distribution groups are active within the last 6 months.

In our company, we create a new distribution group for each project we work on. Since we never get notified when they project is completed, I created a rough script to determine if the group was used within the past 6 months.

Please note this hasn’t been cleaned up at all or polished. This was just a quick script by someone new to PS. Just thought someone else may need it.

$today = Get-Date $sixmonthsago = ($today.AddMonths(-6)) $distributiongroups = Get-DistributionGroup -ResultSize 99999 | Select-Object -ExpandProperty PrimarySmtpAddress $distrogroupcount = (Get-ADGroup -Filter 'GroupCategory -eq "Distribution"').Count $currentcount = 1 #Write Initial File | Clear if it already exists Out-File C:OldDistroGroups.txt foreach ($group in $distributiongroups) { Write-Progress -Activity "Processing Group #$currentcount of $distrogroupcount" $group.Address | Out-File C:OldDistroGroups.txt -Append Get-MessageTrackingLog -start $sixmonthsago -End $today -Recipients $group -ResultSize 1 | measure-object | Out-File C:OldDistroGroups.txt -Append $currentcount = $currentcount + 1 } 

submitted by /u/mrmcweird
[link] [comments]

Leave a Reply