total number of messages send and received with amount of data
Script to show total number of messages send and received with amount of data
add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
[string]::Join(',',("Server,Sent,Received,TotalRecieved,TotalSent")) > "c:\totalsr.csv"
# Get the start date for the tracking log search
$Start = (Get-Date).adddays(-1)
# Get the end date for the tracking log search
$End = (Get-Date)#.adddays(-0)
# Declare an array to store the results
$Results = @()
# Get the SEND events from the message tracking logs
$servers = Get-exchangeserver |?{$_.isHubtransportServer -eq $true}
foreach ($server in $servers)
{
$Sent = Get-MessageTrackingLog -Server $server -EventID SEND -Start $Start -End $End -resultsize unlimited
$SendData = Get-MessageTrackingLog -Server $server -EventID SEND -Start $Start -End $End -resultsize unlimited |Select-Object TotalBytes | Measure-Object -Property TotalBytes -sum
$TotalSent = "{0:N2}" -f ($SendData.Sum / 1MB) + "MB"
# Get the RECEIVE events the message tracking logs
$Received = Get-MessageTrackingLog -Server $server -EventID RECEIVE -Start $Start -End $End -resultsize unlimited
$ReceivedData = Get-MessageTrackingLog -Server $server -EventID RECEIVE -Start $Start -End $End -resultsize unlimited |Select-Object TotalBytes | Measure-Object -Property TotalBytes -sum
$TotalRecieved = "{0:N2}" -f ($ReceivedData.Sum / 1MB) + "MB"
$Count = 1
# Declare a custom object to store the data
$Stats = "" | Select-Object Server,Sent,Receive
# Set the Sent property to the number of messages sent
$Stats.Sent =($Sent | Where-Object { ($_.EventId -eq "SEND")}).Count
# Set the Received property to the number of messages received
$Stats.Receive =($Received | Where-Object { ($_.EventId -eq "Receive")}).Count
# Add the statistics for this mailbox to our results array
foreach ($obj in $Stats)
{
$NoSent = $Stats.Sent
$NoReceived = $Stats.Receive
}
$Count += 1
$Results2 =[string]::Join(',',($Server,$NoSent,$NoReceived,$TotalRecieved,$TotalSent))
$Results2
$Results2 >> "c:\totalsr.csv"
}


Comments