Wednesday, April 6, 2011

Powershell Script to query for an event ID and take action accordingly

$mydate = (Get-date).addminutes(-15)
#$mydate = (Get-date).Addhours(-5)
$EventID = Get-EventLog -LogName System | ? {$_.EventID -eq 429 -and $_.timegenerated -gt $mydate }
#found desired events; Restarting the service
write-host "Found the events; Trying to restart the service"
Get-Service -displayname "IIS Admin" | Restart-Service -force
Get-Service -displayname "Simple Mail Transfer Protocol (SMTP)" | start-Service -force
Get-Service -displayname "World Wide Web Publishing Service" | start-Service -force
Get-Service -displayname "HTTP SSL" | start-Service -force
Get-Service -displayname "Microsoft Exchange Routing Engine" | start-Service -force
} else 
write-host "Events not found; I don't have any actions to do than exit"

No comments:

Post a Comment