I have a single host with 500+ bindings associated to it, and I would like to first purge this host of all its bindings and replace them from a list of bindings in a file. The format of the fill will be a comma separated list of the bindings to assign i.e. site.com,site1.com, etc.
so far I have stared down of first finding the host I want to perform this task on, that trying to remove all the bindings....basically I am trying to:: 1: remove all bindings currently assigned, 2: add bindings from a files.
Update 1: I now have each binding I want to be deleted writing to a file....now how can I get this to delete the actual binding...
Update 2: After pulling my hair out for way too long, I finally have the bindings getting purged and a new binding added to the selected domain. All I have to do know is hook up an insert look reading in a file for a list of bindings to add....
OPTION EXPLICIT
DIM CRLF, TAB, strServer, objWebService, domains, oIIS, oBindingNew, oSite
TAB = CHR( 9 )
CRLF = CHR( 13 ) & CHR( 10 )
IF WScript.Arguments.Length = 1 THEN
strServer = WScript.Arguments( 0 )
ELSE
strServer = "localhost"
END IF
SET objWebService = GetObject( "IIS://" & strServer & "/W3SVC" )
EnumWebsites objWebService
SUB EnumWebsites( objWebService )
DIM objWebServer, objWebServerRoot, strBindings
FOR EACH objWebServer IN objWebService
IF objWebserver.Class = "IIsWebServer" THEN
IF objWebserver.ServerComment = "MobileCC" THEN
SET objWebServerRoot = GetObject(objWebServer.adspath & "/root")
WScript.Echo _
"Site ID = " & objWebserver.Name & CRLF & _
"Comment = """ & objWebServer.ServerComment & """ " & CRLF & _
"State = " & State2Desc( objWebserver.ServerState ) & CRLF & _
"Path = " & objWebServerRoot.path & CRLF & _
"LogDir = " & objWebServer.LogFileDirectory & _
""
' Enumerate the HTTP bindings (ServerBindings) and
' SSL bindings (SecureBindings)
strBindings = EnumBindings( objWebServer.ServerBindings ) & _
EnumBindings( objWebServer.SecureBindings )
IF NOT strBindings = "" THEN
' Output current bindings
WScript.Echo "IP Address" & TAB & _
"Port" & TAB & _
"Host" & CRLF & _
strBindings
END IF
' Reset Bindings for this domain
objWebserver.Put "ServerBindings", ""
objWebserver.SetInfo
' add a new binding
domains="www.NEWBINDING.com"
Set oIIS = GetObject("winmgmts:root\WebAdministration")
Set oBindingNew = oIIS.Get("BindingElement").SpawnInstance_
oBindingNew.BindingInformation = "*:80:" & domains
oBindingNew.Protocol = "http"
Set oSite = oIIS.Get("Site.Name='MobileCC'")
oSite.Bindings= array(oBindingNew)
oSite.put_
END IF
END IF
NEXT
FOR EACH objWebServer IN objWebService
IF objWebserver.Class = "IIsWebServer" THEN
IF objWebserver.ServerComment = "MobileCC" THEN
' Enumerate the HTTP bindings (ServerBindings) and
' SSL bindings (SecureBindings)
strBindings = EnumBindings( objWebServer.ServerBindings ) & _
EnumBindings( objWebServer.SecureBindings )
IF NOT strBindings = "" THEN
' Output current bindings
WScript.Echo "IP Address" & TAB & _
"Port" & TAB & _
"Host" & CRLF & _
strBindings
END IF
END IF
END IF
NEXT
END SUB
FUNCTION EnumBindings( objBindingList )
DIM i, strIP, strPort, strHost
DIM reBinding, reMatch, reMatches
SET reBinding = NEW RegExp
reBinding.Pattern = "([^:]*):([^:]*):(.*)"
FOR i = LBOUND( objBindingList ) TO UBOUND( objBindingList )
' objBindingList( i ) is a string looking like IP:Port:Host
SET reMatches = reBinding.Execute( objBindingList( i ) )
FOR EACH reMatch IN reMatches
strIP = reMatch.SubMatches( 0 )
strPort = reMatch.SubMatches( 1 )
strHost = reMatch.SubMatches( 2 )
' Do some pretty processing
IF strIP = "" THEN strIP = "All Unassigned"
IF strHost = "" THEN strHost = "*"
IF LEN( strIP ) < 8 THEN strIP = strIP & TAB
EnumBindings = EnumBindings & _
strIP & TAB & _
strPort & TAB & _
strHost & TAB & _
""
NEXT
EnumBindings = EnumBindings & CRLF
NEXT
END FUNCTION
FUNCTION State2Desc( nState )
SELECT CASE nState
CASE 1
State2Desc = "Starting (MD_SERVER_STATE_STARTING)"
CASE 2
State2Desc = "Started (MD_SERVER_STATE_STARTED)"
CASE 3
State2Desc = "Stopping (MD_SERVER_STATE_STOPPING)"
CASE 4
State2Desc = "Stopped (MD_SERVER_STATE_STOPPED)"
CASE 5
State2Desc = "Pausing (MD_SERVER_STATE_PAUSING)"
CASE 6
State2Desc = "Paused (MD_SERVER_STATE_PAUSED)"
CASE 7
State2Desc = "Continuing (MD_SERVER_STATE_CONTINUING)"
CASE ELSE
State2Desc = "Unknown state"
END SELECT
END FUNCTION