IIS 6 Host Header Scripting

Posted on 2004-10-14
Last Modified: 2008-01-09
I have the need to add and/or delete host headers from a specific web site via scripting or some other automated process.  I am familiar with iisweb.vbs but it appears to only allow the creation and deletion of web sites, not their host headers.

I have administrative access to the server, so permissions should not be an issue.

Thank you,
Question by:Aristippus
  • 2
  • 2
LVL 34

Accepted Solution

Dave_Dietz earned 500 total points
ID: 12313837
Put the following in a VBS file:
SiteInstance = 1                     'Default Web Site - test value - modify for use

IPAddress = ""          'test value - modify for use - leave blank for 'All Unassigned'

PortNumber = "80"                  'default

HostHeader = "localhost"         'test value - modify for use - set to blank to remove
IIsObjectPath = "IIS://localhost/W3SVC/" & SiteInstance ' & "/ServerBindings"
Set IIsObject = GetObject(IIsObjectPath)

IIsObject.Put "ServerBindings", IPAddress & ":" & PortNumber & ":" & HostHeader



Dave Dietz

Author Comment

ID: 12314631

Thanks for the reply, but that script 'changes' the host header and other information.

I need the ability to 'add' and remove additional host headers.

Hopefully this script can be modified to produce the desired results.

Thank you,

Author Comment

ID: 12316287
Dave's script didn't allow for what I needed, but it did lead me in the right direction.

IIS object does NOT support ADS_PROPERTY_APPEND so it needs a work around (load existing into an array, redim array adding element, rewrite the properties).

It also tests to ensure that the host header does not already exist.

The working script:

strADsPath = "IIS://localhost"
strKey = "W3SVC/1"
strAttribute = "ServerBindings"
strEntry = ""
Set objKey = GetObject(strADsPath & "/" & strKey)

' Check to see whether the entry is already in the
' collection. If it is, quit and inform
For Each strValue in arrValue
      If strValue = strEntry Then
            WScript.Echo "The entry: " & strEntry & _
                  " is already present in " & strAttribute & "." & _
                  " The script will now quit."
      End If

' Add a new item to the array.
Redim Preserve arrValue(uBound(arrValue) + 1)
' Add the value to the new item in the array.
arrValue(uBound(arrValue)) = strEntry

' Update the object with the existing values
' and the new value if it wasn't already present.
objKey.PutEx ADS_PROPERTY_UPDATE, strAttribute, arrValue

For Each strValue in arrValue
      WScript.Echo strValue
LVL 34

Expert Comment

ID: 12316289
I was just working on something like this -  just nowhere near as elegant.....  :-)

Dave Dietz

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is an ISAPI filter?   •      It's an assembly (.dll file) that can add or change the way IIS works.   •      They can be enabled globally for your web server or on a site-by-site basis.   When the IIS server receives a request, enabling the ISAPI fi…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now