【Exchange server】Get-MailTrafficTopReport

#在EXO中有Get-MailTrafficTopReport,官網: https://docs.microsoft.com/en-us/powershell/module/exchange/get-mailtraffictopreport?view=exchange-ps 這個report能夠很直觀的查處必定時間內每一個郵箱的發送量,可是在本地Exchange服務器中卻沒有。web

#如下腳本調用了Exchange服務器的get-messagetrackinglog,以及.count()方法,來拿到和EXO get-mailtraffictopreport同樣的發送數據shell

#There is Get-MailTrafficTopReport in EXO, official website: https://docs.microsoft.com/en-us/powershell/module/exchange/get-mailtraffictopreport?view=exchange-ps This report can be intuitively investigated for a certain period of time The sending volume of each mailbox, but not in the local Exchange server.服務器

#The following script calls the get-messagetrackinglog of the Exchange server and the .count() method to get the same sending data as EXO get-mailtraffictopreportdom

#The below parts needs to be your Exchange server accepted domains
#如下是您本地Exchange服務器上配置的域名
$AcceptedDomains = @("speridian.com","truecoverage.com","sesameindia.com","speridiantec.onmicrosoft.com","finalign.com")
#================================================
#No need to modify the below parts
#如下部分無需更改
$StartDate = Get-Date (Read-Host -Prompt 'Enter the start date, Eg.  05/01/2020 14:00:00')
$StartDate = $StartDate.tostring("MM/dd/yyyy hh:mm:ss")
$endDate =  Get-Date (Read-Host -Prompt 'Enter the end date, Eg.  05/08/2020 18:00:00')
$endDate = $endDate.tostring("MM/dd/yyyy hh:mm:ss")
$CSV = Read-Host "Enter the Export CSV file location (E.g C:\temp)"

$result = @()

$Filter = ""
$i = 0
Foreach($AcceptedDomain in $AcceptedDomains)
{
if($i -eq 0)
{

$Filter = '($_.recipientaddress -notlike "*' + $AcceptedDomain + '*")'

}else{

$Filter += ' -and ($_.recipientaddress -notlike "*' + $AcceptedDomain + '*")'

}
$i++
}

$mailoxes = get-mailbox -resultsize unlimited

$Count = 0
Foreach($mailbox in $mailboxes)
{
    $Count++

    $Percent = ($Count/($mailboxes.count)) * 100

    Write-Progress -Activity "Search in Progress" -Status "$Percent% Complete:" -PercentComplete $Percent;

$Tracking = Get-MessageTrackingLog -Start $StartDate -End $EndDate -Sender $mailbox.primarysmtpaddress -resultsize unlimited| where{($filter)}

$result += [PScustomobject]@{
    Sender = $mailbox.primarysmtpaddress
    Count = $tracking.count
    }
}

$result | export-csv ($CSV+"\OutboundMailTrafficReport"+$runDate+".csv") -NoTypeInformation -Encoding utf8
相關文章
相關標籤/搜索