Thursday, October 20, 2011

Count Number of Messages sent to Distribution Group

I created this script to tell me how many messages had been sent to each of a list of distribution groups in the last 30 days. It's really useful if you are trying to find groups that aren't used often for cleanup purposes.

#Get all transport servers so we can search across all of them
$hubs=get-TransportServer

#where test.txt contains a list of email addresses
$groups=get-content "C:\MessageTrackingRobin\test.txt"

#For each email address in test.txt, count how many messages were sent to it between the start and end dates, then output that information into count.txt in comma delimited format
foreach ($group in $groups){
$count = ($hubs| get-messagetrackinglog -start "09/19/2011 12:00AM" -End "10/20/2011 11:59PM" -recipients $group)
$output=$group + "," + $count.count
add-content count.txt $output
}

No comments: