1

我遇到了以下脚本的问题,该脚本会以看似随机的时间间隔报告已收到 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 -

通过 Theo 的一些提示和一些研究,脚本现在可以运行了!对于路人来说,所做的更改可以在下面找到:

$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
4

0 回答 0