Email trace script for daily report RRS feed

  • Question

  • Hi Guys,

    I wanted to run this script on daily basis (in automated) that will extract previous day logs and instead of saving to local I will need to send the export to email address. 

    Get-ExchangeServer | where {$_.isHubTransportServer -eq $true -or $_.isMailboxServer -eq $true} | Get-MessageTrackingLog -Recipients:email@address.com -EventID "DELIVER" -Start "07/30/2018 00:00:00" -End "07/31/2018 00:00:00" | Select @{Name='Recipients';Expression={[string]::join(";", ($_.Recipients))}}, Sender, EventId, Timestamp, Source, MessageSubject | Export-CSV -Path C:\Users\user\Desktop\MessageTracking.csv

    I appreciate you help.


    • Edited by Uddan Wednesday, August 1, 2018 1:26 AM missed details
    Tuesday, July 31, 2018 2:07 PM


All replies

  • help send-mailmessage -online

    Follow the examples.


    Tuesday, July 31, 2018 2:17 PM
  • Hi Uddan,

    Thanks for your question.

    1. If you want to run the scripts on daily basis(in automated), you can use Task Scheduler to run the script automatically every day. About how to configure to run a PowerShell Script into Task Scheduler.

    Refer to the following link:


    2. You want to get the log from the previous day.


    You can define a variable to get the yesterday's time and format it to match the parameter of Get-MessageTrackingLog cmdlet.

    3. You can use the command send-mailmessage to  send the export to email address.

    For example:

    Send-MailMessage -From "User01 <user01@example.com>" -To "User02 <user02@example.com>", "User03 <user03@example.com>" -Subject "Sending the Attachment" -Body "Forgot to send the attachment. Sending now." -Attachments "data.csv" -Priority High -dno onSuccess, onFailure -SmtpServer "smtp.fabrikam.com"

    Refer to the following link:


    Best Regards,


    • Marked as answer by Uddan Monday, August 6, 2018 12:26 AM
    Wednesday, August 1, 2018 7:34 AM