IIS status detection and restart

by hamd at 2012-10-03 01:17:41

Hello everyone,
I am new in Windows world especially in Powershell, I want to detect the status of IIS if it is stop/ or my server is blocked it restart it automatically.
Can anyone tell me how to do it

by coderaven at 2012-10-03 05:06:51
Instead of using PowerShell for that right off the bat, I would start by looking at the Recovery tab in the Properties of the service. You can just edit the recovery information for each IIS related service. Another option would be to create a scheduled task that is executed on an event log entry, you should at least receive a service X stopped event beyond any errors that may have caused the issue. Keep in mind that the second option there could cause the system to get in a endless loop of crashing and starting the service that is why it is preferred to use the Recovery Tab. If it does become a problem and you want to do it via PowerShell, look up the Register-WMIEvent command.

if we just want to start if stopped

If ((Get-Service -Name ServiceName).Status -eq "Stopped") { Start-Service -Name ServiceName }
by hamd at 2012-10-03 05:54:06
Thanks for reply, I am Linux user and I have done such thing in scripting for Apache, I did try your code and found the IIS Service (IISADMIN). but
it did not worked since I stopped manually the IIS service. Sorry I am really new and it is totally different for me.
I would appreciate a lot if you can write me something step by step or any link?
by beakerman29 at 2012-10-31 10:36:19
Okay so basic information so I can help you better. Please provide the following:

1. Is the server hosting multiple sites.
2. .NET applications or not ?
3. When you say detect status are what exactly are you looking at. IE doing a call to the webserver and if it returns a 404 status or takes over x seconds to return you want to recycle.