Hello,
Yes, the script is ready. It can be used in a Business Rule, Custom Command or Scheduled Task to find out when a message was las sent to the distribution list, on which the Rule, Command or Task is executed. In the script, $exchangeServer specifies the fully qualified domain name (FQDN) of your Exchange Server. Modify it to match your environment.
$exchangeServer = "exchangeserver.domain.com" # TODO: Modify me
# Get the message tracking log for the distribution list
$session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
Import-PSSession -session $session -AllowClobber -DisableNameChecking
$messageTrackingLog = Get-MessageTrackingLog -Recipients "%mail%" -ResultSize Unlimited | Select-Object sender, timestamp | Sort timestamp -Descending
Remove-PSSession -Session $session
if ($messageTrackingLogt -eq $NULL)
{
$Context.LogMessage("There were no messages sent to this distribution list", "Information")
return
}
$sender = $messageTrackingLog[0].Sender
$timeStamp = $messageTrackingLog[0].TimeStamp
$Context.LogMessage("Last message received from '$sender' on '$timeStamp'", "Information")
For your task, you can, for example, create a Custom Command that can be executed on a distribution list to find out the time when the distribution list was last sent to. To create such a Custom Command:
- Create a new Custom Command.
- On the 2nd step of the Create Custom Command wizard, select the Group object type.
- On the 3rd step, add the Run a program or PowerShell script action and paste the above script in the Script field.