$PeriodIndays = 7
$EndPeriod = Get-date -hour 0 -minute 0 -second 0
$StartPeriod = ($EndPeriod).AddDays( -$PeriodIndays ) $PathFile = 'c:\EmailSendAndreceived.html' $From = $StartPeriod $To = $EndPeriod [Int64] $intSent = 0 [Int64] $intRec = 0 [Int64] $intSentSize = 0 [Int64] $intRecSize = 0 $Total = 0 $TotalSent = 0 $TotalRec = 0 $MailPerDay = @() Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 Do { $From = $From.AddDays(1) $To = $From.AddDays(1) $intSent = $intRec = $intSentSize = $intRecSize = 0 # (Get-TransportServer) |
Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To | ForEach { If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER") { $intSent++ $intSentSize += $_.TotalBytes } If ($_.EventId -eq "DELIVER") { $intRec++ $intRecSize += $_.TotalBytes } } $props = [ordered]@{ Date=$From Sent=$intSent SentSizeMB=[Math]::Round($intSentSize/1MB, 0) Recived=$intRec RecivedSizeMB=[Math]::Round($intRecSize/1MB, 0) TotalPerDayInMB=[Math]::Round(($intRecSize+$intSentSize)/1MB, 2) TotalPerDayInGB=[Math]::Round(($intRecSize+$intSentSize)/1GB, 2) } $obj = New-Object -TypeName PSObject -Property $props $MailPerDay += $obj $TotalSent += $intSentSize $TotalRec += $intRecSize } While ($To -lt (Get-Date)) $MailPerDay | ft Write-Host "всего отправлено за отчетный период $([Math]::Round( $TotalSent/1GB, 2)) гигабайт" Write-Host "всего получено за отчетный период $([Math]::Round( $TotalRec/1GB, 2)) гигайбайт" Write-Host "всего получено и отправлено за период $([Math]::Round( ($TotalSent + $TotalRec)/1GB, 2)) гигабайт" $frag1 = $MailPerDay | sort -Property Date -Descending | ConvertTo-Html -As table -Fragment -PreContent "<h2>всего получено за период $([Math]::Round( $TotalSent/1GB, 2)) <br> всего отправлено за период $([Math]::Round( $TotalRec/1GB, 2))<br>всего отправлено и получено за период $([Math]::Round( ($TotalSent + $TotalRec)/1GB, 2))</h2>" | Out-String Write-Verbose 'definiting CSS' $head = @' <style> body { background-color:#ffffff; font-family:Tahoma; font-size:12pt; } td, th { border:1px solid black; border-collapse:collapse; } th { color:white; background-color:black; } table, tr, td, th { padding: 2px; margin: 0px } table { font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif; font-size: 14px; border-radius: 10px; border-spacing: 0; text-align: center; } th { background: #BCEBDD; color: white; text-shadow: 0 1px 1px #2D2020; padding: 10px 20px; } th, td { border-style: solid; border-width: 0 1px 1px 0; border-color: white; } th:first-child, td:first-child { text-align: left; } th:first-child { border-top-left-radius: 10px; } th:last-child { border-top-right-radius: 10px; border-right: none; } td { padding: 10px 20px; background: #F8E391; } tr:last-child td:first-child { border-radius: 0 0 0 10px; } tr:last-child td:last-child { border-radius: 0 0 10px 0; } tr td:last-child { border-right: none; } </style> '@ $Date = Get-Date $rep = ConvertTo-HTML -head $head -PostContent $frag1 -PreContent "<h1>Email Sent received $Date</h1>" | Out-String $rep | Out-File $PathFile
Источник: https://habr.com/post/310348/
$StartPeriod = ($EndPeriod).AddDays( -$PeriodIndays ) $PathFile = 'c:\EmailSendAndreceived.html' $From = $StartPeriod $To = $EndPeriod [Int64] $intSent = 0 [Int64] $intRec = 0 [Int64] $intSentSize = 0 [Int64] $intRecSize = 0 $Total = 0 $TotalSent = 0 $TotalRec = 0 $MailPerDay = @() Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 Do { $From = $From.AddDays(1) $To = $From.AddDays(1) $intSent = $intRec = $intSentSize = $intRecSize = 0 # (Get-TransportServer) |
Get-MessageTrackingLog -ResultSize Unlimited -Start $From -End $To | ForEach { If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER") { $intSent++ $intSentSize += $_.TotalBytes } If ($_.EventId -eq "DELIVER") { $intRec++ $intRecSize += $_.TotalBytes } } $props = [ordered]@{ Date=$From Sent=$intSent SentSizeMB=[Math]::Round($intSentSize/1MB, 0) Recived=$intRec RecivedSizeMB=[Math]::Round($intRecSize/1MB, 0) TotalPerDayInMB=[Math]::Round(($intRecSize+$intSentSize)/1MB, 2) TotalPerDayInGB=[Math]::Round(($intRecSize+$intSentSize)/1GB, 2) } $obj = New-Object -TypeName PSObject -Property $props $MailPerDay += $obj $TotalSent += $intSentSize $TotalRec += $intRecSize } While ($To -lt (Get-Date)) $MailPerDay | ft Write-Host "всего отправлено за отчетный период $([Math]::Round( $TotalSent/1GB, 2)) гигабайт" Write-Host "всего получено за отчетный период $([Math]::Round( $TotalRec/1GB, 2)) гигайбайт" Write-Host "всего получено и отправлено за период $([Math]::Round( ($TotalSent + $TotalRec)/1GB, 2)) гигабайт" $frag1 = $MailPerDay | sort -Property Date -Descending | ConvertTo-Html -As table -Fragment -PreContent "<h2>всего получено за период $([Math]::Round( $TotalSent/1GB, 2)) <br> всего отправлено за период $([Math]::Round( $TotalRec/1GB, 2))<br>всего отправлено и получено за период $([Math]::Round( ($TotalSent + $TotalRec)/1GB, 2))</h2>" | Out-String Write-Verbose 'definiting CSS' $head = @' <style> body { background-color:#ffffff; font-family:Tahoma; font-size:12pt; } td, th { border:1px solid black; border-collapse:collapse; } th { color:white; background-color:black; } table, tr, td, th { padding: 2px; margin: 0px } table { font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif; font-size: 14px; border-radius: 10px; border-spacing: 0; text-align: center; } th { background: #BCEBDD; color: white; text-shadow: 0 1px 1px #2D2020; padding: 10px 20px; } th, td { border-style: solid; border-width: 0 1px 1px 0; border-color: white; } th:first-child, td:first-child { text-align: left; } th:first-child { border-top-left-radius: 10px; } th:last-child { border-top-right-radius: 10px; border-right: none; } td { padding: 10px 20px; background: #F8E391; } tr:last-child td:first-child { border-radius: 0 0 0 10px; } tr:last-child td:last-child { border-radius: 0 0 10px 0; } tr td:last-child { border-right: none; } </style> '@ $Date = Get-Date $rep = ConvertTo-HTML -head $head -PostContent $frag1 -PreContent "<h1>Email Sent received $Date</h1>" | Out-String $rep | Out-File $PathFile
Источник: https://habr.com/post/310348/
Комментариев нет:
Отправить комментарий