Recycling ApplicationPool if 503 error is detected in HTTP.SYS error log

Search a error pattern in the HTTP.SYS error log and recycles the application pool if finded

# Definition of the log file to search in
$LastLog = Get-ChildItem C:\WINDOWS\system32\LogFiles\HTTPERR | Sort -Property LastWriteTime | Select -Last 1
$File = "C:\WINDOWS\system32\LogFiles\HTTPERR\" + $LastLog
# Assuming the website ID is '1'
$Pattern = "503 1 AppOffline"
$Find = Select-String -Path $File -Pattern $Pattern -Quiet -SimpleMatch
# Recycling the ApplicationPool 'ASP.NET v4.0 32 bit' if the searched string has been found in the error log
if ($Find -eq $true) {Restart-WebAppPool "ASP.NET v4.0 32 bit"}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Scroll to Top