So I recently had to do some work on a server that required stopping all sites in IIS but without stopping IIS itself. Here’s the short post on how I did that. Now of course I needed to have all the sites turned back on again. Just restarting IIS wouldn’t do what I needed – it seems to remember what sites were running before the reset. So, here’s a quick little script, which is just the inverse of the previous script, to start all sites.
c:\windows\system32\inetsrv\appcmd.exe list site /xml /state:"$=stopped" | appcmd start site /in
There you go. Simple as could be. This loops through and lists all the sites currently with their running state set to “stopped”, pipes it into the next command, which just starts each of the sites in the list.
By the way this is super fast. Even on a server with hundreds of sites it only took a second or two to run.
Happy IIS hosting! :)
Why not just use iisreset /STOP to stop IIS? and iisreset /START it’s built in to IIS and accessed from the cli.
or just iisreset /NOFORCE to restart iis gracefully. See below for CLI usage:
I do like your script though and think it’s useful if you wanted to stop just websites and not all IIS services.
IISRESET.EXE (c) Microsoft Corp. 1998-1999
/RESTART Stop and then restart all Internet services.
/START Start all Internet services.
/STOP Stop all Internet services.
/REBOOT Reboot the computer.
/REBOOTONERROR Reboot the computer if an error occurs when starting,
stopping, or restarting Internet services.
/NOFORCE Do not forcefully terminate Internet services if
attempting to stop them gracefully fails.
/TIMEOUT:val Specify the timeout value ( in seconds ) to wait for
a successful stop of Internet services. On expiration
of this timeout the computer can be rebooted if
the /REBOOTONERROR parameter is specified.
The default value is 20s for restart, 60s for stop,
and 0s for reboot.
/STATUS Display the status of all Internet services.
/ENABLE Enable restarting of Internet Services
on the local system.
/DISABLE Disable restarting of Internet Services
on the local system.
I only wanted to stop the sites, not all IIS services.
To stop web sites, they’re are also vbs script examples admsrv you can stop any site individually using the metabase root name. I see now you just wanted to stop the sites, not FTP or SMTP I am guessing. In fact, there is a com object you can stop right from a script using it.
Correct – needed to stop the sites without impacting the other IIS services. COM? Ick. People still use COM? :)
Thank you Brad, God bless you and Merry Christmas
More help about control “IIS services”