A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Use Get-MessageTraceV2 twice—once with the users as senders and once as recipients—split the 30-day period into intervals of no more than 10 days, continue any 5,000-row result sets, deduplicate them, and export the combined results to one CSV.
Get-MessageTraceV2 can search the last 90 days, but each query is limited to a 10-day range and 5,000 results. Both SenderAddress and RecipientAddress accept multiple addresses. Larger result sets must be continued using the last row’s Received and RecipientAddress values.^1^
Bulk 30-day trace script
Create users.csv:
EmailAddress
[Email]
[Email]
[Email]
Run the following from Exchange Online PowerShell:
Connect-ExchangeOnline
$addresses = @(Import-Csv .\users.csv |
ForEach-Object EmailAddress |
Where-Object { $_ } |
Sort-Object -Unique)
$start = (Get-Date).ToUniversalTime().AddDays(-30)
$end = (Get-Date).ToUniversalTime()
$output = "C:\Reports\MessageTrace-30Days.csv"
New-Item -ItemType Directory -Path (Split-Path $output) -Force | Out-Null
$results = [System.Collections.Generic.List[object]]::new()
try {
for ($chunkStart = $start; $chunkStart -lt $end; $chunkStart = $chunkEnd) {
$chunkEnd = $chunkStart.AddDays(10)
if ($chunkEnd -gt $end) { $chunkEnd = $end }
foreach ($direction in 'Sent','Received') {
$queryEnd = $chunkEnd
$cursorRecipient = $null
$previousCursor = $null
do {
$p = @{
StartDate = $chunkStart
EndDate = $queryEnd
ResultSize = 5000
ErrorAction = 'Stop'
}
if ($direction -eq 'Sent') { $p.SenderAddress = $addresses }
else { $p.RecipientAddress = $addresses }
if ($cursorRecipient) {
$p.StartingRecipientAddress = $cursorRecipient
}
$page = @(Get-MessageTraceV2 @p)
foreach ($row in $page) {
$row | Add-Member DirectionMatched $direction -Force
$results.Add($row)
}
if ($page.Count -eq 5000) {
$last = $page[-1]
$cursor = '{0:o}|{1}' -f $last.Received,
$last.RecipientAddress
if ($cursor -eq $previousCursor) {
throw "The continuation cursor did not advance: $cursor"
}
$previousCursor = $cursor
$queryEnd = $last.Received
$cursorRecipient = $last.RecipientAddress
}
} while ($page.Count -eq 5000)
}
}
$results |
Sort-Object MessageTraceId, RecipientAddress, Received -Unique |
Export-Csv -Path $output -NoTypeInformation -Encoding UTF8
}
catch {
Write-Error "Message trace export failed: $($_.Exception.Message)"
throw
}
finally {
Disconnect-ExchangeOnline -Confirm:$false
}
The output timestamps are UTC. Adjacent chunks and the separate sent/received searches can overlap—for example, a message sent from one listed user to another—so the final Sort-Object -Unique removes duplicate trace rows. Exchange Online recommends narrow date ranges and precise filters for query performance.^2^
The documented throttling threshold is 100 requests in a rolling five-minute window. For a large address list or high-volume tenant, divide the input into smaller batches if throttling occurs.^1^
Permissions
The account needs message-trace permissions. Supported assignments include:
- Organization Management in Exchange Online; or
- Exchange Administrator; or
- Global Administrator, although Microsoft recommends using the least-privileged role.^2^
Alternative for very large result sets
If the expected total is too large for efficient interactive querying, use Start-HistoricalSearch. It produces server-generated CSV reports for data up to 90 days old, with a limit of 100,000 lines per CSV and 250 submitted historical searches per 24 hours.^3^
Run separate reports for sent and received traffic:
Start-HistoricalSearch -ReportTitle "Users-Sent-30Days" `
-ReportType MessageTrace -StartDate $start -EndDate $end `
-SenderAddress $addresses -NotifyAddress "[Email]"
Start-HistoricalSearch -ReportTitle "Users-Received-30Days" `
-ReportType MessageTrace -StartDate $start -EndDate $end `
-RecipientAddress $addresses -NotifyAddress "[Email]"
These commands create two downloadable reports; they do not directly produce one local CSV. Download both from Exchange admin center → Mail flow → Message trace → Downloadable reports, then import, deduplicate, and merge them locally. Reports covering more than 10 days are generated from archived data and can take several hours.^2^
References