Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (2024)

Windows OS Hub / Exchange / Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server

You can use the Get-MessageTrackingLog cmdlet in the Exchange Management Shell to analyze mail flow, message forensics and to get different information about messages sent or received by a specific mailbox in your email organization. In this article, I will show several examples of PowerShell one-liner commandswhich I often use to track messages on Exchange Server 2016/2013/2010 and Office 365 (Exchange Online).

Let me remind you that the Exchange transport logs are located in the %ExchangeInstallPath%TransportRoles\Logs\MessageTracking folder. And the most efficient and flexible way to analyze message tracking logs in the Exchange is to use the Get-MessageTrackingLog cmdlet.

First of all, consider the main Get-MessageTrackingLog parameters that you can use to filter events in the logs. The following cmdlet parameters are used the most often:

  • Sender – search by sender;
  • Recipients — search by recipient;
  • Server – search on the specific transport server;
  • Start “11/30/2019 08:00:00” -End “12/18/2019 21:00:00” — search for the specific period of time;
  • MessageSubject — search by message subject;
  • EventID – search by Exchange event (as a rule, the following codes are used: RECEIVE, SEND, FAIL, DSN, DELIVER, BADMAIL, RESOLVE, EXPAND, REDIRECT, TRANSFER, SUBMIT, POISONMESSAGE, DEFER);
  • messageID – track by a message ID.

If you run the Get-MessageTrackingLog cmdlet without any parameters, all events from the Exchange transport logs for the last 30 days will be displayed. The cmdlet displays the last 1,000 events only. To remove this restriction, use the –ResultSize Unlimited parameter. (It is not recommended to do it without some additional filter parameters due to potentially high load on your transport server.)

You can display the information about your Exchange events page-by-page using this command:

Get-MessageTrackingLog | Out-Host –Paging

Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (1)

To display the data in the table format and adjust the column width, the Format-Table cmdlet is used:

Get-MessageTrackingLog | Format-Table –AutoSize

If several Hub Transport servers is used in your Exchange organization, you will need to specify the name of a server to search as an argument of the –Server parameter . Or run the message tracking command for each of your Hub Transport servers with the pipe:

Get-TransportServer | Get-MessageTrackingLog

Let’s display all emails for the last 24 hours ((Get-Date).AddHours(-24)), in which a recipient from @gmail.com domain is specified:

Get-MessageTrackingLog -Start (Get-Date).AddHours(-24) -ResultSize unlimited | where {[string]$_.recipients -like "*@gmail.com"}

Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (2)

To display all emails sent by the specific user through the certain server in a given period of time use the command below (only the specific tracking fields will be displayed in the report):

Get-MessageTrackingLog -ResultSize unlimited –Sender "[emailprotected]” –server rome-hub-01 -Start "11/30/2019 06:00:00" -End "12/13/2019 22:00:00" |select-object Timestamp,Sender,Recipients,MessageSubject,EventId|ft

Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (3)

Let’s find all emails sent by a user to another one and export the search results into a CSV file:

Get-MessageTrackingLog -Sender "[emailprotected]" -Recipients "[emailprotected]" -ResultSize unlimited –server rome-hub-01| Select-Object Timestamp,Sender,{$_.recipients},MessageSubject | Export-Csv -Path "C:\Export\exchange\exchange_tracking_logs.csv" -Encoding Default -Delimiter ";"

You can search by the message subject. To display all emails with “test” word in the subject field, run the following command. (To display the results in a separate graphic window as a table with the convenient sorting, filtering and search features, you can use the Out-gridview cmdlet.)

Get-MessageTrackingLog -MessageSubject "test" -ResultSize unlimited –server rome-hub-01| Select-Object Timestamp,Sender, {$_.recipients}, MessageSubject | out-gridview

Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (4)

You can search by the specific message ID (you can get it from the message header in Outlook):

Get-MessageTrackingLog -messageID "[emailprotected]" -ResultSize unlimited –server rome-hub-01| Select-Object Timestamp,Sender, {$_.recipients}, MessageSubject

To count the number of incoming email messages for the specific mailbox for the last 7 days, run the following command:

(Get-MessageTrackingLog -EventID "RECEIVE" -Recipients "[emailprotected]" -ResultSize unlimited).Count

You can display the more insteresing message statistics. For example, you want to see how many emails from different senders from the gmail.com have been received by users of your company during the last 5 days (we will display the total number of emails sent by each external sender):

Get-MessageTrackingLog -EventId "Receive" -Start (Get-Date).AddDays(-5) -ResultSize Unlimited | Where-Object {$_.Sender -like "*@gmail.com"} | Group-Object Sender | Sort-Object Count -Descending | Format-Table *

Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (5)

To find emails stored in the Exchange user mailboxes, use the Search-Mailbox cmdlet.

Office 365 allows you to perform message tracking logs search from the Exchange Admin Center (EAC). Go to the Mail Flow -> Message Trace. Fill in the search fields. This is actually the web interface for the Get-MessageTrackingLog cmdlet, which allows the user to generate PowerShell tracking command in a simple web form.

Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (6)

The methods considered above will help you to get the statistics on the sent and received messages in your Exchange system and diagnose different email transport problems.

Get-MessageTrackingLog: Search Message Tracking Logs on Exchange Server | Windows OS Hub (2024)
Top Articles
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 6159

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.