How to add an additional host header to an IIS 6.0 website using the command line or a batch file

I use IIS 6.0 to host several hundred websites. I use IIS's Host Headers feature to allow all these websites to share one IP address. I have created batch files to make adding new websites to the server very quick and easy. The only tricky part about setting up new websites from batch file (or the command line) is that Microsoft's ADSUTL utility does not correctly add host headers like it says it does- rather than appending the new headers, it blindly sticks them in and possibly covers existing host headers that might already be set up.

DOWNLOAD IISBatchUtils.ZIP

In there is a batch file that will correctly add a host header to an IIS 6.0 site. The syntax for this batch file is...

ADDHEADER site_name new_header

So, for example, if you have a site named "josh.com" and you want to add the alias "crappy.com" to it, you'd use...

ADDHEADER josh.com crappy.com

...then, you'd almost certainly also want to add the alias "www.crappy.com" too, so you'd then run...

ADDHEADER josh.com www.crappy.com

You can also optionally specify a specific IP address to bind to at the end of the command line like this...

ADDHEADER josh.com www.crappy.com 192.168.15.1

To use the batch file, you'll also need the included ADSUTIL2.VBS. This is a modified version of Microsoft's ADSUTIL that correctly appends the new host header.

EXTRAS

In the ZIP file, you'll also find some other other handy files for automating the job of setting up new websites on an IIS 6.0 server...

ADDALL.BAT Completely sets up a new domain by creating the website, creating the subdirectory, creating the user account, creating a "comming soon" page, adding permissions to the new directory, creating the DNS zone, adding the DNS records, and creating the IIS aliases for the "www" host. Very handy.
ADDZONE.BAT Creates a new DNS zone using the DNSCMD command.
ADDWEB.BAT Creates a new IIS website using the ADSUTIL.VBS script
ADDALIAS.BAT Adds an alias for an existing website.
ADDSPF.BAT Creates an SPF record for the domain's mail server.
ADDPAGE.BAT Creates a customized "Comming Soon" hoempage.

Note that you'll need to edit these files to reflect the IP addresses and directory structure of your web and mail servers. My webserver is at 216.254.115.185 and my directory structure is set up so each website is located in "D:\WEBSITES\domain_name" where domain_name is the name of the domain.

Also note that these batch files use the included XCACLS.VBS to set up directory permissions rather than the built-in CACLS command. Amazingly, the CACLS command has a bug that makes it completely useless, even in Win2003 SP1. If you try to use CACLS for this, it will just mess up your permissions and make your computer very sad. It is *amazing* that Microsoft has known about this bug for five years and never fixed it. It is even more amazing that they don't let you download the hotfix, you have to actually call them on the phone to get it.

UPDATES

4/10/2007 Updated ADDHEADER.BAT so that you can now optionally specify an IP address for the newly added host header. Leaving the IP blank will use the default value "bind to all unused IP addresses".
  Updated ADDUSER.BAT so that it will now set the password on the newly created account to "never expire". People who only log in via FTP have no good way to reset their passwords, so this way they do not have to.

###