Both the IIS site and the Application Pool currently exist. I get the site identifier first, and then proceed to get the WMI object and assign an existing App Pool to the site.
I am getting an error on the "set objSite..." line that an object is required for objWMIService. I am sure I am missing something, just not obvious to me.
Here's the code:
strAppPool =
"WebAppPool"
Set
objAppPool = GetObject("IIS://localhost/w3svc/AppPools/" & strAppPool)
Set
IISOBJ = getObject("IIS://LocalHost/W3SVC")For each Object in IISOBJ
if (Object.Class = "IIsWebServer") then
if (Object.ServerComment = "MyWeb") thenstrSiteID = Object.Name
end ifend if
next
strSitePath =
"IIS://localhost/W3SVC/" & strSiteID
Set
objSite = objWMIService.Get("IIsWebServerSetting='" & strSitePath & "'")
Set
objVirtualDirectory = objWMIService.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")
' Assign the Pool to the Site
objVirtualDirectory.AppPoolID = strAppPool
objVirtualDirectory.Put_()