Install ADFS on Azure VM step by step

how to track email in office 365 via powershell?

Mail tracking Via PowerShell in office 365

 

Some time we get request where users complains that they did not receive email sent by some other users, in that situation exchange admin have option to track emails,

If you have an In-house exchange environment it is pretty easy task to track email via the Mail Flow Troubleshooter tool provided in Exchange management console, But when it comes to office 365 the tool is not available to use and tracking a particular email is bit hectic, In office365 we are provided with the option of Email Tracking via (Exchange Control Panel) ECP and windows PowerShell, ECP option is pretty simple but provide limited details, whereas PowerShell tracking provide good amount of tracking information. In this article I will describe how to track an email via Powershell.

Note:  As per current Microsoft documentation you can only track email upto past 7 days, hope they increase this soon to 30 days.

Requirement to track an email

·         Sender Email Id

·         Recipient Email

·         Subject (Optional: required just to match if you tracked the correct message )

·         Send Time and Time zone (Optional: required just to match if you tracked the correct message )

 

To Track the email we will use the following PowerShell cmd lets.

·         Search-MessageTrackingReport

·         Get-MessageTrackingReport

To Track the email first run the Search-MessageTrackingReport Command

I used $temp array to save the results for later use in Get-MessageTrackingReport Command

$Temp = Search-MessageTrackingReport -Identity “Sunil Chauhan” -Sender "testuser@LetsExchange.in" –BypassDelegateChecking

This (-BypassDelegateChecking) switch allow you to run Search-MessageTrackingReport on a user’s mailbox without you have right on user mailbox, hence it is mandatorily to use this switch else you will run into an error if you run the command without this switch.

Once you have run the above command you have all the tracking info saved in $temp Array.

You can export the tracking results to csv file or you can simply see result on PowerShell screen by simply typing the $temp and hit enter, to export the result to csv type the below command

Ø  $temp | export-csv  ”temp.csv” –notype

When you have gone through the results you can check a particular email tracking info in the $temp array using below mentioned method.

Example : suppose you only want to check the 2nd record, you can run the below command on PowerShell and it will only display the 2nd record from the $temp Array.

$temp[01]

Note: PowerShell Array start counting record from 0 so to access 2nd record I used $temp[01] switch

 

Now you can run Get-MessageTrackingReport for a particular message or for the entire array

For running the Get-MessageTrackingReport for a particular e-mail in $temp array use the below command format.

Get-MessageTrackingReport -Identity $temp[01].MessageTrackingReportID -ReportTemplate Summary

As mentioned previously always use (–BypassDelegateChecking) switch, else you will run into errors,

Below is the demonstration of the error message you are going to get if you do not use this switch.

 

So use this switch and when you run the command with the –BypassDelegateChecking you will see the result showing as below screenshot.

Example: Sample Command to get the tracking report for the very first message in $temp Array.

Get-MessageTrackingReport -Identity $temp[0].MessageTrackingReportID -ReportTemplate Summary -BypassDelegateChecking

This command get the Delivery Status report, you can see the message status in Attribute RecipentTrackingEvents, this attribute contains information about the receipent email address ,Mail delivery status and time of the delivery.

 

To run the command for the entire $temp array you can run the below command.

$temp | % {Get-MessageTrackingReport -Identity $_.MessageTrackingReportID -ReportTemplate summary -BypassDelegateChecking}

Now you know and can manipulate the results the way you like, you can pipe and select a particular attribute you want and export the result to csv or you can just see them on PowerShell window.

Example: Display the result on screen for only FromAddress, RecipientTrackingevents

$temp | % {Get-MessageTrackingReport -Identity $_.MessageTrackingReportID -ReportTemplate summary -BypassDelegateChecking} | ft fromaddress,RecipientTrackingEvents –auto

Example: Export the entire Tracking result to Csv

$temp | % {Get-MessageTrackingReport -Identity $_.MessageTrackingReportID -ReportTemplate summary -BypassDelegateChecking} | Export-Csv "test.csv" -NoTypeInformation

I hope you like my article I wish you all happy Tracking in Office 365. J

This is end of the document, for more information you can follow the below TechNet article.

http://technet.microsoft.com/en-us/library/dd351082(v=exchg.150).aspx

 

Comments