Have you ever wondered what the distribution of the number of recipients per e-mail in your organization is?
The following script will go through every e-mail received by Exchange and group the results by the number of recipients.
Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -EventID RECEIVE -Start "07/05/2012 16:40" | ? {$_.Source -eq "STOREDRIVER"} | Select RecipientCount | Group RecipientCount | Select @{Name="Recipients"; Expression={[Int] $_.Name}}, Count | Sort Recipients
Alternatively, you can group them in batches depending on which format you want the output.
[Int] $1 = $2 = $5 = $10 = $30 = $50 = $75 = $100 = $150 = $200 = $250 = $big = 0
Get-TransportServer | Get-MessageTrackingLog -ResultSize Unlimited -EventID RECEIVE -Start "07/05/2012" | ? {$_.Source -eq "STOREDRIVER"} | Select RecipientCount | ForEach {
If ($_.RecipientCount -eq 1) { $1++ }
If ($_.RecipientCount -eq 2) { $2++ }
If ($_.RecipientCount -gt 2 -and $_.RecipientCount -le 5) { $5++ }
If ($_.RecipientCount -gt 5 -and $_.RecipientCount -le 10) { $10++ }
If ($_.RecipientCount -gt 10 -and $_.RecipientCount -le 30) { $30++ }
If ($_.RecipientCount -gt 30 -and $_.RecipientCount -le 50) { $50++ }
If ($_.RecipientCount -gt 50 -and $_.RecipientCount -le 75) { $75++ }
If ($_.RecipientCount -gt 75 -and $_.RecipientCount -le 100) { $100++ }
If ($_.RecipientCount -gt 100 -and $_.RecipientCount -le 150) { $150++ }
If ($_.RecipientCount -gt 150 -and $_.RecipientCount -le 200) { $200++ }
If ($_.RecipientCount -gt 200 -and $_.RecipientCount -le 250) { $250++ }
If ($_.RecipientCount -gt 250 -and $_.RecipientCount -le 300) { $300++ }
If ($_.RecipientCount -gt 300) { $big++ }
}
Write-Host "1, $1"
Write-Host "2, $2"
Write-Host "Between 3 and 5, $5"
Write-Host "Between 6 and 10, $10"
Write-Host "Between 11 and 30, $30"
Write-Host "Between 31 and 50, $50"
Write-Host "Between 51 and 75, $75"
Write-Host "Between 76 and 100, $100"
Write-Host "Between 101 and 150, $150"
Write-Host "Between 151 and 200, $200"
Write-Host "Between 201 and 250, $250"
Write-Host "Between 251 and 300, $300"
Write-Host "More than 300, $big"
# Exchange Online - Script to find senders with messages having more than 500 recipients
ReplyDelete# Set the start date for the message trace (10 days ago from the current date)
$StartDate = (Get-Date).AddDays(-10)
# Set the end date for the message trace (1 day in the future to ensure all data is included up to the current date)
$EndDate = (Get-Date).AddDays(1)
# Set the sender domain filter for the messages (e.g., messages from contoso.com)
$Domain = "pramod7.onmicrosoft.com"
# Run the Get-MessageTrace cmdlet to get the message trace data within the defined date range
# Filter the results to include only messages from the specified sender domain
# Group the results by the sender's email address
# For each group, calculate the number of unique recipients and filter to show only senders with more than 1000 unique recipients
Get-MessageTrace -Start $StartDate -End $EndDate | `
Where-Object { $_.SenderAddress -like "*@$Domain" } | `
Group-Object -Property SenderAddress | `
Select-Object Name, @{Name="UniqueRecipients";e={($_.Group | Select-Object -ExpandProperty RecipientAddress | Sort-Object -Unique).Count}} | `
Where-Object { $_.UniqueRecipients -gt 100 }