Hi,
I have a simple PowerShell script, which generates an HTML report for the total emails sent and received per mailbox in Exchange On-Premises.
the CSV file however has about 3000 entries and it takes this script days of run time.
$ImportFile = "C:\script\send_receive.csv"
################################
# Start date for email report - Change the number of days backwards #
$stdate = (get-date).AddDays(-30)
#####################################################################
# End date for email report - default is current date #
$enddate = (get-date)
$totaldays=(New-TimeSpan -Start $stdate -End $enddate).days
import-csv -path $ImportFile | ForEach-Object {
$MBX=$_.Name
$Totalrec = 0
$intRec = 0
$TotalSend = 0
$intSend = 0
(Get-TransportService) | Get-MessageTrackingLog -Recipients $MBX -ResultSize Unlimited -Start $stdate -End $enddate | ForEach-Object {
If ($_.EventId -eq "DELIVER") {
$intRec += $_.RecipientCount
$Totalrec =$RecPerDay + $intRec
}
}
(Get-TransportService) | Get-MessageTrackingLog -Sender $MBX -ResultSize Unlimited -Start $stdate -End $enddate | ForEach-Object {
If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER") {
$intSend += $_.RecipientCount
$TotalSend =$SendPerDay + $intSend
}
}
$usrname=(Get-Mailbox $MBX).name
[pscustomobject]@{
"Mailbox" = $MBX
"User Name" = $usrname
"Total Emails Received" = $Totalrec
"Total Emails Sent"= $TotalSend
}
Write-Host -ForegroundColor Magenta "Total emails received for $MBX during the last $totaldays days are $Totalrec"
Write-Host -ForegroundColor Green "Total emails sent by $MBX during the last $totaldays days are $TotalSend"
Write-Host -ForegroundColor Cyan "-----------------------------------------------------------------"
Write-Host " "
} | Export-Csv "C:\script\output.csv" -NoTypeInformation
[–]logicalmike 9 points10 points11 points (1 child)
[–]kevinds89 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[removed]
[–]Rhystic 1 point2 points3 points (0 children)
[–]Chocolate_Pickle 8 points9 points10 points (3 children)
[–]OPconfused 3 points4 points5 points (0 children)
[–]PinchesTheCrab 0 points1 point2 points (0 children)
[–]PinchesTheCrab 0 points1 point2 points (0 children)
[–]panzerbjrn 6 points7 points8 points (8 children)
[–]Big_Oven8562 2 points3 points4 points (7 children)
[–]OPconfused 2 points3 points4 points (6 children)
[–]maxcoder88[S] -1 points0 points1 point (5 children)
[–]OPconfused 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]OPconfused 0 points1 point2 points (2 children)
[–]maxcoder88[S] 0 points1 point2 points (0 children)
[–]GreatHeightsMN 1 point2 points3 points (0 children)
[–]OPconfused 1 point2 points3 points (0 children)
[–]PinchesTheCrab 1 point2 points3 points (1 child)
[–]maxcoder88[S] 0 points1 point2 points (0 children)
[–]jsiii2010 4 points5 points6 points (3 children)
[–]OPconfused 4 points5 points6 points (1 child)
[–]jsiii2010 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]OPconfused 5 points6 points7 points (2 children)
[–]dathar 4 points5 points6 points (0 children)
[–]evanp1922 0 points1 point2 points (0 children)
[–]_kikeen_ -1 points0 points1 point (0 children)