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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top