sashoalm
sashoalm

Reputation: 79447

Restart IIS site and its apppool from a batch file

I have a site where I need to restart the site and its apppool each time I make changes. When I'm debugging one of the scripts it becomes a chore to do it manually each time (it's 5-6 clicks).

enter image description here enter image description here

Is there a way to automate it in a batch file?

Edit: I found how to restart the apppool from https://stackoverflow.com/a/38607626/492336, but I need to restart the site as well:

C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"MYAPPPOOLNAME"

Upvotes: 8

Views: 9901

Answers (1)

sashoalm
sashoalm

Reputation: 79447

After some searching and trial and error, I came up with a short script, where "Default Web Site" is the name of the site to restart:

C:\Windows\System32\inetsrv\appcmd stop apppool /apppool.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd stop site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"Default Web Site"

If you get this error:

message:The WAS service is not available - try starting the service first.

Try to execute with admin privileges.

Upvotes: 10

Related Questions