Monitoring the App pool status manually is very difficult for all the time, and some times we may aware that App pool has stopped while browsing the URL so to avoid those type of scenario below PowerShell script will help of check the status of the application pool recycle and start if its stopped. So you can make integrate the below script in Task scheduler for specific interval time for checking the status of the App pool and start if it stopped. You may also include the email trigger if its stopped and started by the script.
Executed and Tested Version
OS : Windows 10
IIS : 10.0.15063.0
PowerShell version : 5.1.15063.1155
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# Load IIS module: Import-Module WebAdministration # SET AppPool Name $AppPoolName = "DefaultAppPool" #Testing if a String is NULL or EMPTY. if ([string]::IsNullOrWhiteSpace($AppPoolName)) { Write-Output "$AppPoolName does not exist" } else { try { #Determines whether all elements of a file or directory path exist. if (Test-Path IIS:\AppPools\$AppPoolName){ # Start App Pool if stopped else restart #Get the runtime state of the DefaultAppPool and checking the status if ((Get-WebAppPoolState($AppPoolName)).Value -eq "Stopped"){ Write-Output "Starting IIS app pool" #starting the App Pool Start-WebAppPool $AppPoolName } else { Write-Output "Application pool is Running successfully" } } } catch { Write-Output $_.Exception.Message throw } } |
What do you think?
I hope you have idea of how to check the application pool status and start using Powershell . I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.