I tried to use ADSUTIL but I found 2 limitations:
1) it doesn't append to the list, it replaces the list.
2) the command prompt is limited to 9 arguments.
So I decided to write my own vbscript
' ***************************************************************
' * AddHostHeader.vbs By Vittorio Pavesi (www.vittorio.tk) *
' * *
' * Add Host Header to a specific IIS Site *
' ***************************************************************
Dim objWWW, WebSitePath
Dim BindingArray()
Dim i
if Wscript.arguments.count<3 then
Wscript.echo "Script can't run without correct argument"
Wscript.echo "Correct usage: Cscript AddHostHeader.vbs SiteID Port HostHeader"
Wscript.echo "Correct usage: Cscript AddHostHeader.vbs 21 80 www.mySite.com"
Wscript.quit
end if
ID = Wscript.arguments.Item(0)
Port = Wscript.arguments.Item(1)
NewHostHeader = Wscript.arguments.Item(2)
i = 0
Set objWWW = GetObject("IIS://localhost/W3SVC/" & ID)
For each item in objWWW.ServerBindings
redim preserve BindingArray(i)
BindingArray(i) = item
i = i + 1
next
redim preserve BindingArray(i)
BindingArray(i) = ":" & port & ":" & NewHostHeader
objWWW.ServerBindings = BindingArray
objWWW.SetInfo()
wscript.echo "Successfully added binding for: " & port & ":" & ucase(NewHostHeader)
1 commenti:
exellent thank you.
just what I needed.
converted your code to vb.net and automated a boring process.
Post a Comment