日ごとの送受信された手紙の数

交換サーバーで、ユーザーが毎日何メガバイト単位の統計で送受信する文字数を調べる必要がありました。インターネットを研究した後、スクリプトがテキスト出力を行うことに満足していないことがわかりました。 スクリプトが再設計されました:







交換サーバーから日ごとに送受信された手紙の数を受信します。



#### Variables ##### #      ,    $PeriodIndays = 7 #    ,      $EndPeriod = Get-date -hour 0 -minute 0 -second 0 #         //  "09/5/2016" $StartPeriod = ($EndPeriod).AddDays( -$PeriodIndays ) #################################################################################### $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 { # Sent E-mails If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER") { $intSent++ $intSentSize += $_.TotalBytes } # Received E-mails 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)) "
      
      





美しいHTMLレポートを取得するには、たとえば、以下のメールで拡張スクリプトを送信するには:







 #### Variables ##### #      ,    $PeriodIndays = 7 #    ,      $EndPeriod = Get-date -hour 0 -minute 0 -second 0 #         //  "09/5/2016" $StartPeriod = ($EndPeriod).AddDays( -$PeriodIndays ) #   html  $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 { # Sent E-mails If ($_.EventId -eq "RECEIVE" -and $_.Source -eq "STOREDRIVER") { $intSent++ $intSentSize += $_.TotalBytes } # Received E-mails 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)) " ############# HTML generating ############# $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
      
      





後者はhtmlファイルを生成し、デフォルトでCディレクトリに配置します。



All Articles