Adding sites to IIS7 from the command line

A quick note on how to create a site in IIS7 from the command line (cmd.exe). It is very handy if you need to create 100+ sites.

Start cmd.exe as administrator and go to the following directory:

cd %windir%\system32\inetsrv

Without this the system will not see appcmd and you will get the following error:

'appcmd.exe' is not recognized as an internal or external command
operable program or batch file.

The syntax of creating a site is the following:

appcmd add site /name:www.site_name /bindings:http://www.site_name:80,http://site_name:80 /physicalPath:C:\inetpub\wwwroot\www.site_name

With the following command you can change the home directory of the site. It stays a mystery to me why you have to use ‘vdir’ and not ‘site’:

appcmd.exe set vdir "site_name/" -physicalPath:"C:\inetpub\wwwroot\folder_name"

Related posts:

  1. The list of sites in IIS6