AlexLaforge
AlexLaforge

Reputation: 532

ApplicationPool Class Object properties not available in WMI

I am managing my IIS Application Pools using a local VBScript on the machine, or through an ASP page running under a highly-privileged identity.

The Microsoft documentation lists all the available properties and methods for an ApplicationPool Class Object on this page https://msdn.microsoft.com/fr-fr/library/ms690608.

Altough I am able to use the .Recycle, .Start and .Stop methods, and the .Name property, all the other methods and properties are not available for the Application Pool, like .GetState, .AutoStart, .ManagedPipelineMode...

Is the documentation broken ?

'For VBSCRIPT
Set o_Wbem_Locator = CreateObject("WbemScripting.SWbemLocator")
Set o_Wbem_Service = o_Wbem_Locator.ConnectServer("MyServerName", "root/MicrosoftIISv2")
Set o_Wbem_AppPoolsCollection = o_Wbem_Service.ExecQuery("SELECT * FROM IISApplicationPool")
For Each o_Wbem_AppPoolInstance In o_Wbem_AppPoolsCollection
    'Work
    o_Wbem_AppPoolInstance.Recycle

    'Work
    WScript.Echo o_Wbem_AppPoolInstance.Name

    'DOES NOT Work
    WScript.Echo o_Wbem_AppPoolInstance.GetState

    'DOES NOT Work
    WScript.Echo o_Wbem_AppPoolInstance.ManagedPipelineMode
Next

Upvotes: 1

Views: 1233

Answers (1)

AlexLaforge
AlexLaforge

Reputation: 532

HERE IS THE SOLUTION :)

As stated by @Kul-Tigin in the comments, I was connecting to the wrong Namespace, and querying the wrong Object Class.

NAMESPACE

  • "root/MicrosoftIISv2" is suitable for IIS 6
  • "root/WebAdministration" is suitable for IIS 7 [and Higher]

OBJECT CLASS TO QUERY

  • "SELECT * FROM IISApplicationPool" is suitable for IIS 6
  • "SELECT * FROM ApplicationPool" is suitable for IIS 7 [and Higher]

So the correct working code to manage IIS 7+ Application Pools using WMI from Vbscript or ASP is the following one :

'For VBSCRIPT
Set o_Wbem_Locator = CreateObject("WbemScripting.SWbemLocator")

'Suitable for IIS 6
'Set o_Wbem_Service = o_Wbem_Locator.ConnectServer("MyServerName", "root/MicrosoftIISv2")

'Suitable for IIS 7+
Set o_Wbem_Service = o_Wbem_Locator.ConnectServer("MyServerName", "root/WebAdministration")

'Suitable for IIS 6
'Set o_Wbem_AppPoolsCollection = o_Wbem_Service.ExecQuery("SELECT * FROM IISApplicationPool")

'Suitable for IIS 7+
Set o_Wbem_AppPoolsCollection = o_Wbem_Service.ExecQuery("SELECT * FROM ApplicationPool")


For Each o_Wbem_AppPoolInstance In o_Wbem_AppPoolsCollection
    'Works in IIS 6 and in IIS 7+
    o_Wbem_AppPoolInstance.Recycle    

    'Works in IIS 6 and in IIS 7+
    WScript.Echo o_Wbem_AppPoolInstance.Name    

    'DOES NOT Work in IIS 6
    'Works in IIS 7+
    WScript.Echo o_Wbem_AppPoolInstance.GetState    

    'DOES NOT Work in IIS 6
    'Works in IIS 7+
    WScript.Echo o_Wbem_AppPoolInstance.ManagedPipelineMode
Next

I wish to kindly thank @Kul-Tigin for pointing this fundamental difference in the required syntax, and many thanks to all the other commentators that contributed to make me able to polish my IIS Application Pool management. I am now able to automate some actions to ensure that my Application Pools are up, well, and running ;)

Upvotes: 3

Related Questions