Good Morning
At my company we currently have a lot of distribution groups actually we have more groups than employees lol
It seems that after a group stopped being used no one ever decommissioned them. Is it possible to use the powershell built into exchange 2010 to view when was the last time the Distribution group received an email
So far i have the below but it is not returning results.
# counts both static and dynamic lists being used
# change the xdays value to however far back you wanna go
# verify how far back your messagetrackinglogs go for accurate results
$xdays = 365
$table = @()
$report = @()
$lists = @()
$results = Get-TransportServer | get-messagetrackinglog -eventid expand -resultsize unlimited -start (get-date).addDays(-$xdays) | sort timestamp -desc
if ($results)
{
$data = $results | group relatedrecipientaddress | sort name
$lists = get-distributiongroup -resultsize unlimited | select alias,primarysmtpaddress
$lists += Get-DynamicDistributionGroup -ResultSize unlimited | select alias,primarysmtpaddress
$lists = $lists | sort alias
foreach ($list in $lists)
{
$check = $null
$check = $data | ?{$_.name -like "$($list.primarySMTPaddress.tostring())"}
if ($check)
{
$table += New-Object -TypeName PSObject -Property @{
MailingList = $list.alias.toLower()
Hits = $check.count
LastUsed = ($check | select -expand group | select -first 1).TimeStamp
}
}
else
{
$table += New-Object -TypeName PSObject -Property @{
MailingList = $list.alias.toLower()
Hits = 0
LastUsed = $null
}
}
}
$table | Select-Object MailingList,Hits,LastUsed | Export-Csv -Path ".\MailingListUsage-$(Get-Date -f 'MMddyy').csv" -NoTypeInformation
}
else
{"No Results"}