Powershell事件日志发送无尽的电子邮件

时间:2019-03-20 19:49:33

标签: powershell events logging windows-server-2012

https://www.ryadel.com/en/event-viewer-send-notification-e-mail-messages-with-powershell/之后的大部分时间里,我都以

结尾
$event = get-eventlog -LogName Application -Message *Arc* -newest 1 | Where-Object {$_.Source -notlike "MsiInstaller"}

if ($event.Message -like "*Arc*")
{
    $PCName = $env:COMPUTERNAME
    $EmailBody = $event | format-list -property * | out-string
    $EmailFrom = "$PCName sasquatch@bigfoot.com"
    $EmailTo = "you_cant_find@me.com"
    $EmailSubject = $event.Source
    $SMTPServer = "smtp.server"
    Write-host "Sending Email"
    Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer
}
else
{
    write-host "No error found"
    write-host "Here is the log entry that was inspected:"
    $event
}

然后将其中一项作为任务附加到Windows应用程序日志。当满足查询参数时,无论是通过链接中包含的测试方法还是符合条件的实际应用程序事件,我不仅会收到一封电子邮件,而且还会一遍又一遍地不断收到同一封电子邮件。

在计划的任务设置中,我尝试了每个选项,其中包括“如果任务已在运行,则适用以下规则”中的所有选项。该任务在一个服务帐户下运行,并且与该任务无关的许多其他计划任务运行良好,就像多年来一样。电子邮件服务器也没有问题,不会导致它无休止地发送电子邮件,因为它可以为25,000个用户提供服务,而他们会在大约0.2秒内注意到它。

enter image description here

我认为PS很古怪,我也尝试过:

$event = get-eventlog -LogName Application -Message *Arc* -newest 1 | Where-Object {$_.Source -notlike "MsiInstaller"}
$PCName = $env:COMPUTERNAME
$EmailBody = $event | format-list -property * | out-string
$EmailFrom = "$PCName sasquatch@bigfoot.com"
$EmailTo = "you_cant_find@me.com"
$EmailSubject = $event.Source
$SMTPServer = "smtp.server"
Write-host "Sending Email"
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer

同样的问题:电子邮件不断循环。这是在Windows Server 2012 R2数据中心上。任务计划程序的历史记录一直显示Task Scheduler did not launch task "\Event Viewer Tasks\ArcGIS Application" because instance "{0b7a77d1-41f9-4ad9-b943-a98d1a22aa9f}" of the same task is already running.

0 个答案:

没有答案