31

How do I restart a single website in IIS7+ using commandline only?

Same functionality as the circled menu item in the image - but from the commandline.

enter image description here

Iisreset does not have any options to deal with individual sites, and I found some ancient references to Iisweb.vbs, which seems to be outdated.

Kjensen
  • 1,039
  • 10
  • 28
  • 39
  • I normally do `cls & %windir%\system32\inetsrv\appcmd stop site /site.name:"SITENAME" & SLEEP 2 & %windir%\system32\inetsrv\appcmd start site /site.name:"SITENAME"` where `SITENAME` can be retrieved using `%windir%\system32\inetsrv\appcmd list site` mentioned in the accepted answer below. – Dan Atkinson Jun 05 '20 at 13:01

4 Answers4

43

What you are looking for is the appcmd command. Take a look at its TechNet manual.

To list your sites out:

For 32-bit OS: %windir%\system32\inetsrv\appcmd list site

For 64-bit OS: %windir%\syswow64\inetsrv\appcmd list site

To restart your site, stop it and then start it:

appcmd start site /site.name:string

or

appcmd stop site /site.name:string

Rick
  • 103
  • 1
  • 4
Wesley
  • 32,690
  • 9
  • 82
  • 117
  • Just a note - i was in the iisexpress directory (cd \Program Files\IIS Express) and was baffled as to where the start option had gone. Make sure you are actually using the correct web server i.e. C:\Windows\System32\inetsrv fo IIS. Just to avoid others making my mistake – Crab Bucket Sep 15 '15 at 10:03
  • Any thought why the above command would give me `'stop' is not recognized as an internal or external command, operable program or batch file.`? I have verified that `start` and `stop` commands work individually, but not through piping. – dotNET Mar 01 '16 at 14:30
  • @dotNET I suppose that Wesley had in mind either `start` or `stop`, rather than piping. – laika Jan 24 '19 at 11:48
  • 1
    @laika: aaah... sometimes we become so blind. It is so obvious now that I look at it. Thanks for pointing out. It was years ago though, don't even remember what I was doing. :) – dotNET Jan 24 '19 at 13:44
  • 4
    Here's an example of calling this (for a site called 'SDL Web'): `%windir%\system32\inetsrv\appcmd stop site /site.name:"SDL Web"` I pasted this into a .bat file and it works a treat - thanks. – Jonathan Williams May 01 '19 at 13:48
  • A side note: there's no guarantee that files of a stopped site will be immediately unloaded. If a script will try to remove them right after the stop command they could be still locked. – montonero Jun 17 '19 at 11:25
  • Is that possible to stop/start remote machine site ? – Mohit M Jul 14 '19 at 15:21
  • Not working for me in the case of stopping an IIS FTP Site on Windows 10 – tsul Nov 26 '21 at 09:31
7

I know this is an old thread and the OP specifically asked for IIS7 and a command line, but since I stumbled here and there were a few recent comments I thought I'd save someone the trouble of searching further for doing the same in IIS10 with PowerShell. This is what works very simply for me to stop and restart a website from a PowerShell Admin prompt:

(replace 'example.com' with your website name)

PS C:\Users\Administrator> Import-Module WebAdministration 
PS C:\Users\Administrator> Stop-WebSite example.com
PS C:\Users\Administrator> Start-WebSite example.com

Hope this helps someone.

4

I'd personally suggest not stopping and starting sites, but recycling the associated Application Pool.

This should be closer to imperceptible for end users, while a stop/start will probably produce 503s while the site's down.

APPCMD LIST WP

APPCMD RECYCLE WP

are the command-line versions of this...

TristanK
  • 9,073
  • 2
  • 28
  • 39
-1

List your existing web sites with:

C:\> iisweb.vbs /query

and you can then restart a specific website by executing:

C:\> iisweb.vbs /stop <website> && iisweb.vbs /start <website>
quanta
  • 51,413
  • 19
  • 159
  • 217