« Previous Next »

Thread: VBScript for changing Application Pool on existing site...

Last post 10-30-2009 5:21 AM by Leo Tang - MSFT. 2 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (3 items)

Sort Posts:

  • 10-28-2009, 3:13 AM

    VBScript for changing Application Pool on existing site...

    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") then

    strSiteID = Object.Name

    end if

    end 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_()

  • 10-30-2009, 1:23 AM In reply to

    Re: VBScript for changing Application Pool on existing site...

    Still haven't managed to figure this out... anyone have a hint?

  • 10-30-2009, 5:21 AM In reply to

    Re: VBScript for changing Application Pool on existing site...

    Hi, 

    macronfactor:

    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_()

    You can still assign the pool to the site by using ADSI:

    strSitePath = "IIS://localhost/W3SVC/" & strSiteID

    Set objVirtualDirectory = Getobject( strSitePath & "/ROOT")

    ' Assign the Pool to the Site

    objVirtualDirectory.AppPoolID = strAppPool

    objVirtualDirectory.SetInfo()

    Leo Tang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (3 items)
Microsoft Communities