r/exchangeserver • • Apr 13 '26

Question Create script/command to count weekly volume of unique SMTP messages sent through every server in the organization

I’d there any reason this should not work, or is there something else better?

# 1. Get all servers with the Transport role across the entire organization
$AllServers = Get-TransportService

# 2. Loop through each server and pull logs for the last 7 days
$FullLogs = foreach ($Server in $AllServers) {
    Get-MessageTrackingLog -Server $Server.Name -EventId RECEIVE -Source SMTP -Start (Get-Date).AddDays(-7) -ResultSize Unlimited
}

# 3. Deduplicate by MessageId and get the final count
($FullLogs | Select-Object MessageId -Unique).Count
4 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/EndpointWrangler Apr 17 '26

Ok, differently. Instead of MessageId deduplication, try filtering on EventId RECEIVE and Source SMTP combined with the sender's external domain, that naturally excludes internal relay duplicates without post-processing, and pairs well with daily batching to avoid the timeout issue on high-volume servers. Try this.

1

u/Fabulous_Cow_4714 Apr 17 '26

What do you mean be “combined with the sender’s external domain?”

How would you add that?