DHCP服務器事件日誌檢測

         系統管理員監測系統事件日誌,如果DHCP服務器出現五天之內的錯誤信息,則將錯誤信息發送到指定管理員的郵箱中。

$body=$null

$dhcplogs=$null

$servicename="dhcpserver"

$smtpsrv="your smtpserver"

$emailfrom="this mail from"

$emailto="your e-mail"

$subject="DHCP 錯誤信息"

$dhcpservice=get-service|?{$_.name -eq $servicename}

if($dhcpservice)

{

 $dhcplogs=get-eventlog system -source -after  ([system.datetime]::now).adddays("-5") -entrytype error

foreach($log in $dhcplogs)

{

  $body+=$log| ft  -wrap|out-string

}

$smtp=new-object net.mail.smtpclient($smtpsrv)

$smtp.send($emailfrom,$emailto,$subject,$body)

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章