Can I use PowerShell instead of AppCmd.exe to monitor IIS state?
-
24-03-2021 - |
Question
I want to write a script that uses appcmd.exe to monitor IIS state - restart a site if it's down and/or restart IIS if it's down.
Can this be done with powershell? is there a more natural/easier method of doing this?
Thanks :-)
Solution
Windows PowerShell is always the Answer! This should do it for your particular question:
# Cycle IIS if it's not running
Get-Service W3SVC |
Where-Object {$_.Status -ne 'Running' } |
Start-Service
Import-Module WebAdministration
# Cycle websites that are not started
Get-Website |
Where-Object { $_.State -ne 'Started' } |
ForEach-Object { $_.Start() }
Hope this Helps
OTHER TIPS
You can use the WebAdministration
module to do it in a more elegant way than using appcmd.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow