Many distribution lists quickly become confusing, but cleaning up distribution lists can be difficult if you don't know how often they are used. I have created a small script that counts how many mails have been sent to a list in the last few days. The time period is customizable. However, it must be ensured that the message tracking logs go back far enough.
Here is the script:
#-----------------------------
# Find unused distributors
# www.frankysweb.de
#
# by Frank Zöchling
# Version 0.1
#
#-----------------------------$unuseddays = „30“
$distrigroups = Get-DistributionGroup
$htservers = get-transportserver
$end = get-date
$start = $end.addDays(-$unuseddays)foreach ($distrigroup in $distrigroups)
{
$mailaddress = $distrigroup.PrimarySmtpAddress
$displayname = $distrigroup.DisplayName
foreach ($htserver in $htservers)
{
$mailsreceive = get-messagetrackinglog -Recipients:$mailaddress -Server $htserver -start $start -end $end -eventid receive | measure-object | foreach-object {$_.count}
$count = $count + $mailsreceive
}$result+=@{$Displayname=“$count“
}$count = 0
}
$result
The
As you can see, the script is not particularly complex and can be quickly adapted to build a PRTG or Solarwinds monitor, for example. Or you can run the script once a month and have the values written to a CSV file, or or or or...