Exchange Online Custom Message Trace Retention (Roadmap 542929) & Automated Get-MessageTraceV2 Archiving Runbook

✨ December 2026 Exchange Online Mail Flow & Compliance Brief
  • Custom Message Trace Retention (Roadmap ID 542929): Rolling out in December 2026, Exchange Online administrators can choose predefined retention periods for Message Trace data to align with regional privacy mandates (e.g., GDPR data minimization) or internal audit requirements—replacing the rigid one-size-fits-all retention model.
  • Get-MessageTraceV2 Rules: Supports up to 90 days of historical trace data, but enforces a strict 10-day maximum span per query and a 5,000-result cap per call.
  • Cursor Pagination Replaces -Page: Unlike legacy Get-MessageTrace, V2 removes the -Page parameter. To export large datasets without missing events, scripts must paginate using -EndDate and -StartingRecipientAddress.

For years, Exchange Online administrators had no control over how long Message Trace metadata lived in the Exchange Admin Center (EAC)—and security teams needing 6-month or 1-year mail-flow audit trails had to build brittle polling jobs against the legacy Get-MessageTrace cmdlet.

In December 2026, Microsoft is rolling out Custom Retention for Message Trace Logs (Microsoft 365 Roadmap ID 542929), giving admins predefined retention choices to match corporate compliance and privacy policies. At the same time, Message Trace V2 (Get-MessageTraceV2) is now the standard PowerShell interface for querying up to 90 days of mail flow telemetry. This guide explains how to plan your retention window and provides a live-tested PowerShell archiving script that handles 10-day window chunking and V2 cursor pagination cleanly.


Architecture: Automated Get-MessageTraceV2 Chunking & Cursor Pagination

1. Auth & Window Split • EXO App-Only Cert Auth • Target Span (Up to 90d) • Auto-Split into ≤10d Chunks Avoids 10-Day Query Error 2. Get-MessageTraceV2 Loop • -ResultSize 5000 (Max) • Check Count == 5000 • Advance Cursor: -EndDate + -StartingRecipientAddress 3. Deduplicate • Key on MessageTraceId + RecipientAddress • Normalize UTC Timestamps Zero Duplicate Rows 4. Cold Archive âś” Daily CSV / JSONL âś” Azure Blob / Sentinel âś” 365+ Day Retention SOC & Audit Ready Roadmap ID 542929 Strategy: Shorter Tenant Retention + Automated SIEM Archiving Shorten EAC Message Trace retention for privacy/GDPR minimization while exporting sanitized metadata to immutable Sentinel/Blob storage.

1. Key Differences: Legacy Get-MessageTrace vs. Get-MessageTraceV2

CapabilityLegacy Get-MessageTrace (Deprecated)Modern Get-MessageTraceV2 (2026 Standard)
Max Historical Depth10 days (older required async Start-HistoricalSearch)90 days direct queryable history
Max Single Query Span10 days10 days (throws error if span exceeds 10 days)
Default Timeframe (No Dates)Last 48 hoursLast 48 hours
Pagination Mechanism-Page and -PageSizeCursor-based: -EndDate + -StartingRecipientAddress
Max Results Per Call5,0005,000 (returns warning with exact next cursor parameters)
Auth SupportEXO PowerShellEXO PowerShell v3.7+ (App-Only Cert Auth recommended)

Live-Verified Pagination Behavior (LAB 365 Dev Tenant)

When Get-MessageTraceV2 hits -ResultSize, Exchange Online returns a warning showing the exact cursor needed for the next batch:
TEXT
WARNING: There are more results, use the following command to get more.
Get-MessageTraceV2 -StartDate "2026-12-01T07:25:20.0000000Z" -EndDate "2026-12-01T10:38:09.1800000Z" -StartingRecipientAddress "[email protected]" -ResultSize 5

Notice that results are returned in reverse chronological order (newest first). To fetch the next page, you pass the Received timestamp and RecipientAddress of the last item in the batch into -EndDate and -StartingRecipientAddress.


2. Production PowerShell Script: Automated Get-MessageTraceV2 Archiver

This script connects unattended using Certificate-Based App-Only Authentication (Connect-ExchangeOnline -AppId ... -CertificateThumbprint ...), slices any requested window (e.g., 30 or 90 days) into compliant 10-day chunks, follows V2 cursor pagination automatically, deduplicates boundary rows, and writes clean CSV archives.

POWERSHELL
#Requires -Modules ExchangeOnlineManagement
<#
.SYNOPSIS
    Automated Exchange Online Message Trace V2 archiver with 10-day chunking and cursor pagination.
.DESCRIPTION
    Live-tested against Exchange Online (ExchangeOnlineManagement v3.11+).
    Handles Get-MessageTraceV2's 10-day query span cap and 5,000-row cursor pagination
    using -EndDate and -StartingRecipientAddress.
.EXAMPLE
    .\Export-MessageTraceV2Archive.ps1 -Organization "contoso.onmicrosoft.com" -AppId "<GUID>" -CertificateThumbprint "<THUMB>" -DaysBack 30
#>

param(
    [Parameter(Mandatory)]
    [string]$Organization,

    [string]$AppId,
    [string]$CertificateThumbprint,

    [ValidateRange(1, 90)]
    [int]$DaysBack = 14,

    [string]$SenderAddress,
    [string]$RecipientAddress,
    [int]$BatchSize = 5000,
    [string]$OutputFolder = ".\MessageTraceV2-Archive"
)

$ErrorActionPreference = "Stop"
if (-not (Test-Path $OutputFolder)) { New-Item -ItemType Directory -Path $OutputFolder | Out-Null }

# 1. Connect to Exchange Online (Unattended Cert Auth preferred)
if ($AppId -and $CertificateThumbprint) {
    Connect-ExchangeOnline -AppId $AppId -CertificateThumbprint $CertificateThumbprint -Organization $Organization -ShowBanner:$false
} else {
    Connect-ExchangeOnline -Organization $Organization -ShowBanner:$false
}

$UtcNow      = (Get-Date).ToUniversalTime()
$GlobalStart = $UtcNow.AddDays(-$DaysBack)
$ChunkEnd    = $UtcNow
$SeenKeys    = [System.Collections.Generic.HashSet[string]]::new()
$AllRecords  = [System.Collections.Generic.List[object]]::new()

Write-Host "[+] Exporting Message Trace V2 from $($GlobalStart.ToString('u')) to $($UtcNow.ToString('u'))..." -ForegroundColor Cyan

# 2. Slice total range into <= 10-day windows
while ($ChunkEnd -gt $GlobalStart) {
    $ChunkStart = $ChunkEnd.AddDays(-10)
    if ($ChunkStart -lt $GlobalStart) { $ChunkStart = $GlobalStart }

    Write-Host "  -> Querying window: $($ChunkStart.ToString('yyyy-MM-dd HH:mm')) UTC to $($ChunkEnd.ToString('yyyy-MM-dd HH:mm')) UTC" -ForegroundColor Yellow

    $CursorEnd       = $ChunkEnd
    $CursorRecipient = $null
    $PageNumber      = 0

    do {
        $PageNumber++
        $Params = @{
            StartDate  = $ChunkStart
            EndDate    = $CursorEnd
            ResultSize = $BatchSize
        }
        if ($CursorRecipient)  { $Params['StartingRecipientAddress'] = $CursorRecipient }
        if ($SenderAddress)    { $Params['SenderAddress']            = $SenderAddress }
        if ($RecipientAddress) { $Params['RecipientAddress']         = $RecipientAddress }

        $Batch = @(Get-MessageTraceV2 @Params -WarningAction SilentlyContinue)
        $Added = 0

        foreach ($Row in $Batch) {
            $UniqueKey = "$($Row.MessageTraceId)|$($Row.RecipientAddress)"
            if ($SeenKeys.Add($UniqueKey)) {
                $AllRecords.Add([PSCustomObject]@{
                    ReceivedUTC      = $Row.Received.ToUniversalTime().ToString("o")
                    SenderAddress    = $Row.SenderAddress
                    RecipientAddress = $Row.RecipientAddress
                    Subject          = $Row.Subject
                    Status           = $Row.Status
                    FromIP           = $Row.FromIP
                    ToIP             = $Row.ToIP
                    SizeBytes        = $Row.Size
                    MessageId        = $Row.MessageId
                    MessageTraceId   = $Row.MessageTraceId
                })
                $Added++
            }
        }

        Write-Host "     Page $PageNumber : Retrieved $($Batch.Count) rows ($Added unique)" -ForegroundColor Gray

        # Advance cursor if batch hit the limit
        if ($Batch.Count -eq $BatchSize) {
            $LastRow         = $Batch[-1]
            $CursorEnd       = $LastRow.Received.ToUniversalTime()
            $CursorRecipient = $LastRow.RecipientAddress
        } else {
            break
        }
    } while ($true)

    $ChunkEnd = $ChunkStart
}

$Timestamp  = (Get-Date).ToString("yyyyMMdd-HHmmss")
$ExportPath = Join-Path $OutputFolder "MessageTraceV2-$Timestamp.csv"
$AllRecords | Export-Csv -Path $ExportPath -NoTypeInformation -Encoding UTF8

Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
Write-Host "`n[+] Archived $($AllRecords.Count) unique message trace events to $ExportPath" -ForegroundColor Green

3. Governance Recommendations for Custom Message Trace Retention (Roadmap 542929)

  1. Align EAC Retention with Privacy Policy: If your legal or DPO team mandates 30-day operational log minimization in M365, set the Exchange Online Message Trace retention accordingly once Roadmap 542929 reaches your tenant—while archiving security-relevant headers (without subject lines if required by PII rules) to Microsoft Sentinel or immutable Azure Blob Storage.
  2. Schedule Daily Incremental Exports: Instead of pulling 90 days at once, schedule Export-MessageTraceV2Archive.ps1 -DaysBack 2 daily via Azure Automation or a hardened scheduled task using App-Only Certificate Auth. The script's MessageTraceId|RecipientAddress deduplication ensures zero overlap.
  3. Pair with Get-MessageTraceDetailV2 for Incident Triage: When investigating a specific delivery failure or transport rule hit, pipe the MessageTraceId and RecipientAddress into Get-MessageTraceDetailV2 for full hop-by-hop diagnostic events.


References & Official Microsoft Documentation

đź’¬ Reader Comments & Feedback

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