u/Fabulous_Cow_4714

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
reddit.com
u/Fabulous_Cow_4714 — 9 days ago