#MsExchange #IAMMEC
So I have been running some discovery scripts on an M&A and wanted to check DL’s and when they were last used. Came up with this ..
$days = 90 Set-ADServerSettings -ViewEntireForest:$true $results = Get-TransportServer | get-messagetrackinglog -eventid expand -resultsize unlimited -start (get-date).addDays(-$days) | sort timestamp -desc $results.count IF(![string]::IsNullOrEmpty($results)) { $report = @() $lists = @() $data = $results | group relatedrecipientaddress | sort name $lists = get-distributiongroup -resultsize unlimited | Select Alias, primarysmtpaddress, Name, RecipientType, OrganizationalUnit, @{Expression={""};Label="Count"}, @{Expression={""};Label="LastUsed"} $lists += Get-DynamicDistributionGroup -ResultSize unlimited | Select Alias, primarysmtpaddress, Name, RecipientType, OrganizationalUnit, @{Expression={""};Label="Count"}, @{Expression={""};Label="LastUsed"} $lists = $lists | sort alias foreach ($list in $lists) { $check = $null $check = $data | ?{$_.name -like "$($list.primarySMTPaddress.tostring())"} if ($check) { $List.Count = $Check.Count $List.LastUsed = ($check | select -expand group | select -first 1).TimeStamp } } } $lists | Export-csv GroupsWithUsage.csv -NoTypeInformation -Encoding Unicode |
Enjoy