PowerShell Script: Message Tracking Across Multiple Exchange Server SE / 2019 Transport Servers

✨ Quick Command β€” Multi-Server Message Tracking in Exchange Server SE / 2019
  • On-Premises Exchange SE / 2019 / 2016: Enumerate all transport nodes with Get-TransportService and pipe to Get-MessageTrackingLog.
  • Exchange Online (Microsoft 365): Get-MessageTrackingLog is on-premises onlyβ€”use Get-MessageTraceV2 in Exchange Online PowerShell v3.

In a multi-server Exchange Server Subscription Edition (SE), 2019, or 2016 organization, inbound and outbound messages can traverse any Mailbox/Transport server in your DAG or AD site. Running Get-MessageTrackingLog on one server at a time is slow and error-prone during an active mail-flow incident.

This updated PowerShell function (Search-ExchangeMessageTracking) automatically discovers all Exchange Transport servers via Get-TransportService (replacing the deprecated Exchange 2010 Get-TransportServer cmdlet), queries them in one pass, and returns unified chronological results.


Multi-Server Message Tracking Flow

Multi-Server Exchange Message Tracking Pipeline 1. Discover Servers Get-TransportService Enumerates all Exchange SE, 2019 & 2016 Transport nodes 2. Query Tracking Logs Get-MessageTrackingLog Filters by Sender, Recipients, MessageSubject & Start/End 3. Sort & Export Aggregates hops by Timestamp across all servers into Table or CSV for root-cause analysis Cloud Tip: For Exchange Online mail flow, use Get-MessageTraceV2 instead of Get-MessageTrackingLog.

PowerShell Function: Search-ExchangeMessageTracking

Save this script as Search-ExchangeMessageTracking.ps1 and dot-source it inside the Exchange Management Shell (. .\Search-ExchangeMessageTracking.ps1):

POWERSHELL
function Search-ExchangeMessageTracking {
    <#
    .SYNOPSIS
        Queries Get-MessageTrackingLog across all Exchange Server SE/2019/2016 Transport services.
    #>
    [CmdletBinding()]
    param(
        [string]$Sender,
        [string]$Recipient,
        [string]$Subject,
        [datetime]$Start = (Get-Date).AddDays(-2),
        [datetime]$End   = (Get-Date),
        [string]$ExportCsvPath
    )

    $Params = @{
        Start      = $Start
        End        = $End
        ResultSize = "Unlimited"
    }
    if ($Sender)    { $Params.Sender         = $Sender }
    if ($Recipient) { $Params.Recipients     = $Recipient }
    if ($Subject)   { $Params.MessageSubject = $Subject }

    $Servers = Get-TransportService
    Write-Host "[*] Querying $($Servers.Count) Exchange Transport server(s)..." -ForegroundColor Cyan

    $Results = foreach ($Srv in $Servers) {
        Get-MessageTrackingLog -Server $Srv.Name @Params |
            Select-Object Timestamp, ServerHostname, EventId, Source, Sender,
                @{ Name = "Recipients"; Expression = { $_.Recipients -join "; " } },
                MessageSubject, ConnectorId, RecipientStatus
    }

    $Sorted = $Results | Sort-Object Timestamp

    if ($ExportCsvPath) {
        $Sorted | Export-Csv -Path $ExportCsvPath -NoTypeInformation -Encoding UTF8
        Write-Host "[+] Exported $($Sorted.Count) tracking events to $ExportCsvPath" -ForegroundColor Green
    }

    return $Sorted
}

Usage Examples

1. Track by Sender and Recipient

POWERSHELL
Search-ExchangeMessageTracking -Sender "[email protected]" -Recipient "[email protected]" |
    Format-Table Timestamp, ServerHostname, EventId, Source, RecipientStatus -AutoSize

2. Track by Subject Across the Last 7 Days and Export to CSV

POWERSHELL
Search-ExchangeMessageTracking `
    -Subject "Quarterly Invoice" `
    -Start (Get-Date).AddDays(-7) `
    -ExportCsvPath "C:\Temp\MessageTracking.csv"


References & Official Microsoft Documentation

πŸ’¬ Reader Comments & Feedback

Did this runbook help, or did Microsoft change a cmdlet or UI menu? Share your feedback below.