Script Repository


Output the last time a distribution list received mail

May 08, 2017
2712

The script outputs the last time when a distribution list received mail. To use the script with Adaxes, you will need to create Custom Commands executed on Group objects.

For more information on creating Custom Commands, see Create a Custom Command.

Parameters:

  • $exchangeServer - specifies the fully qualified domain name or IP address of your Exchange Server.
Edit Remove
PowerShell
$exchangeServer = "exchangeserver.domain.com" # TODO: Modify me

try
{
    # Connect to the Exchange Server
    $session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
    Import-PSSession -session $session -AllowClobber -DisableNameChecking

    # Get the message tracking log for the distribution list
    $messageTrackingLog = Get-MessageTrackingLog -Recipients "%mail%" -ResultSize Unlimited | Select-Object sender, timestamp | Sort timestamp -Descending
}
finally
{
    # Close connection to the Exchange Server
    Remove-PSSession -Session $session
}

if ($messageTrackingLog -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")


Comments ( 0 )
No results found.
Leave a comment