У меня проблема с приведенным ниже сценарием, который с кажущимися случайными интервалами сообщает о получении 0 электронных писемОн запускается в среде Exchange 2016. Я связал изображение результатов также ниже. Любая помощь с устранением неполадок, описанных ниже, будет принята с благодарностью!
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
.$env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -Auto
$nl = [Environment]::NewLine
Set-Culture en-GB
Set-WinSystemLocale en-GB
Set-WinHomeLocation -GeoId 242
Set-WinUserLanguageList en-GB -force
$enGB = New-Object system.globalization.cultureinfo(“en-GB”)
$GBdateShort = Get-Date (get-date).addDays(-1) -format ($enGB.DateTimeFormat.ShortDatePattern)
$GBdateLong = Get-Date (get-date).addDays(-1) -format ($enGB.DateTimeFormat.LongDatePattern)
$mailbox = "countme@test.co.uk"
$emailFrom = "email.stats@test.co.uk"
$emailTo = "recip1@test.co.uk, recip2@test.co.uk, recip3@test.co.uk"
$subject = "Daily Email Report for $mailbox for $GBdate"
$smtpServer = "TEST-EX01"
$StartDateC1 = "$GBdateShort 00:00:00"
$EndDateC1 = "$GBdateShort 05:59:59"
$StartDateC2 = "$GBdateShort 06:00:00"
$EndDateC2 = "$GBdateShort 17:59:59"
$StartDateC3 = "$GBdateShort 18:00:00"
$EndDateC3 = "$GBdateShort 23:59:59"
$receiveCount1 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $StartDateC1 -End $EndDateC1 -EventID "Deliver" | Measure-Object
$receiveCount2 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $StartDateC2 -End $EndDateC2 -EventID "Deliver" | Measure-Object
$receiveCount3 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $StartDateC3 -End $EndDateC3 -EventID "Deliver" | Measure-Object
$receiveCount4 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $StartDateC1 -End $EndDateC3 -EventID "Deliver" | Measure-Object
$receiveCount1String = $receiveCount1.count
$receiveCount2String = $receiveCount2.count
$receiveCount3String = $receiveCount3.count
$receiveCount4String = $receiveCount4.count
$body = "<font face='Consolas' color=#000000>
Mailbox statistics for: <h3><font color=#dd002a>$mailbox</font></h3><br>
Report date: <h3><font color=#dd002a>$GBdateLong ($GBdateShort)</font></h3>
----------------------------------------------------------------------<br><br>
Total no. of e-mails received <u>between <b>Midnight</b> and <b>7:00am</b></u>: <h3><font color=#dd002a>$receiveCount1String</font></h3><br>
Total no. of e-mails received <u>between <b>7:00am</b> and <b>6:00pm</b></u>: <h3><font color=#dd002a>$receiveCount2String</font></h3><br>
Total no. of e-mails received <u>between <b>6:00pm</b> and <b>Midnight</b></u>: <h3><font color=#dd002a>$receiveCount3String</font></h3><br><br><br>
Total no. of e-mails received <u><b>all day</u></b>: <h1><font color=#dd002a>$receiveCount4String</font></h1></font>
</font>"
$HTMLmail = New-Object Net.Mail.Mailmessage $emailFrom, $emailTo, $subject, $body
$HTMLmail.IsBodyHTML=$true
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($HTMLmail)
Изображение, иллюстрирующее вывод:
- РЕДАКТИРОВАТЬ1 -
С некоторыми советами Тео и некоторыми исследованиями сценарий теперь работает! Для прохожих внесенные изменения можно найти ниже:
$startDTcount1 = "$GBdateShort 00:00:00"
$objStartDTcount1 = [datetime]::ParseExact($startDTcount1,'dd/MM/yyyy HH:mm:ss',$enGB)
$endDTcount1 = "$GBdateShort 05:59:59"
$objEndDTcount1 = [datetime]::ParseExact($endDTcount1,'dd/MM/yyyy HH:mm:ss',$enGB)
$startDTcount2 = "$GBdateShort 06:00:00"
$objStartDTcount2 = [datetime]::ParseExact($startDTcount2,'dd/MM/yyyy HH:mm:ss',$enGB)
$endDTcount2 = "$GBdateShort 17:59:59"
$objEndDTcount2 = [datetime]::ParseExact($endDTcount2,'dd/MM/yyyy HH:mm:ss',$enGB)
$startDTcount3 = "$GBdateShort 18:00:00"
$objStartDTcount3 = [datetime]::ParseExact($startDTcount3,'dd/MM/yyyy HH:mm:ss',$enGB)
$endDTcount3 = "$GBdateShort 23:59:59"
$objEndDTcount3 = [datetime]::ParseExact($endDTcount3,'dd/MM/yyyy HH:mm:ss',$enGB)
$receiveCount1 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $objStartDTcount1 -End $objEndDTcount1 -EventID "Deliver" | Measure-Object
$receiveCount2 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $objStartDTcount2 -End $objEndDTcount2 -EventID "Deliver" | Measure-Object
$receiveCount3 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $objStartDTcount3 -End $objEndDTcount3 -EventID "Deliver" | Measure-Object
$receiveCount4 = Get-TransportService | Get-MessageTrackingLog -Recipients $mailbox -Start $objStartDTcount1 -End $objEndDTcount3 -EventID "Deliver" | Measure-Object