我想在Windows Server重新启动或意外closures时发送电子邮件。
我正在阅读一个方法来实现这一点是在系统的日志上查找事件ID 6008,然后发送警报。
什么是完成这个任务的最好方法?
提前致谢。
PS如果可能,我想使用PowerShell脚本。
您需要使用在启动时运行的计划任务来运行如下所示的脚本:
$lastBootTime = Get-CimInstance -ClassName win32_operatingsystem | select lastbootuptime $lastBootTime = $lastBootTime.lastbootuptime $events = Get-EventLog -LogName System -After $lastBootTime | where {$_.eventId -eq 6008} if ($events -ne $null) { Send-MailMessage -From [email protected] -Subject "Unexpected shutdown detected on server" -To [email protected] }