Scripting the creation and configuration of IIS 7 websites

by Mitch Tulloch [Published on 11 May 2010 / Last Updated on 11 May 2010]

You can use Appcmd.exe and other commands to script the creation and configuration of IIS 7 websites.

You can use Appcmd.exe and other commands to script the creation and configuration of IIS 7 websites. This approach is useful if you want to automate the creation and configuration of websites using batch files. It's also useful if you want to create and configure websites in an environment where you have Server Core deployed.

For example, to create a new website named New Site on a Server Core Web server named SEA-SC2, follow these steps:

Create a home directory for the site by using the mkdir command like this:

mkdir C:\newsite

Create a default document in the home directory, for example by typing the following Copy command and then pressing Ctrl+Z as shown here:

copy con C:\newsite\default.htm

This is a test


Create the new site, assigning it a site ID of 2 and bindings of *, which indicates that the new site will listen on all IP addresses bound to the server’s network adapter, and on the default port 80, but only listens for HTTP requests that specify as the host being requested, as follows:

appcmd add site /name:"New Site" /id:2 /physicalPath:C:\newsite /bindings:http//*

SITE object "New Site" added

APP object "New Site/" added

VDIR object "New Site/" added

1 file(s) copied.

Before your new site can respond to HTTP requests issued for, you must create a new CNAME (alias) record in the zone on your Domain Name System (DNS) server so that name queries issued for will return the IP address assigned to To do this, use this command on your DNS server:

dnscmd SEA-DC2 /recordadd www CNAME

Now create a virtual directory named /Addy that maps to the physical folder C:\Code and which belongs to a site named New Site created previously by doing this:

mkdir C:\code

appcmd add vdir /"New Site"/ /path:/addy /physicalPath:C:\code

VDIR object "New Site/addy" added

To create a new application (and also a new virtual directory) named Userinfo beneath the root of the site named New Site, and to map this application (and virtual directory) to the physical directory C:\Apps, do this:

mkdir C:\apps

appcmd add app /"New Site" /path:/userinfo /physicalPath:C\apps

You can also use Appcmd.exe to create and configure application pools and perform many other tasks. Appcmd.exe can be used to configure settings at the server, site, application, or virtual directory level. Appcmd.exe is found in the %WinDir%\System32\Inetsrv, which is not in the system path. This means to use this command, you need to either change your current directory to %WinDir%\System32\Inetsrv or add the \Inetsrv directory to your system path by typing setx path "%path%;C:\Windows\System32\inetsrv" /m and rebooting your computer.

For more information on how to do all these things, see my book Windows Server 2008 Server Core Administrator's Pocket Consultant from Microsoft Press.


The Author — Mitch Tulloch

Mitch Tulloch is a well-known expert on Windows Server administration and cloud computing technologies. He has published over a thousand articles on information technology topics and has written, contributed to or been series editor for over 50 books.

Latest Contributions

Featured Links