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! :)