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”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s