WMI7: Getting the 'Values' Qualifier...
In WMI, there's really not a concept of an Enum datatype. Instead, the datatype is still defined as an int but they allow you to attach metadata to the property to specify the allowable values and its respective Enum name. For example, in c#, you would define an enum similar to:
enum MyEnum
{
Value1 = 1,
Value2 = 2,
Value3 = 3
}
In WMI, you would define the metadata using Qualifiers, which would look like:
[ ValueMap {"1", "2", "3"}, Values {"Value1", "Value2", "Value3"} ]
sint32 ManagedPipelineMode;
Note that you would need to decorate each property with these qualifiers. You definitely lose the code re-use, but such is life in the world of WMI.
Being the tester of the WMI provider for IIS7, I'm responsible for verifying that each WMI property is matched exactly to its configuration definition in the IIS7 schema. In Vista, the properties were defined with both the 'ValueMap' and the 'Values' qualifiers as shown above. In Longhorn Beta 3 however, we wanted the ability to localize these values so we've moved the 'Values' qualifier into a .mfl file...which brings me to the point of this blog.
Since the 'Values' qualifier is now defined in a separate file and is considered to be an 'Amendment' to the property, it is no longer present in the default 'Qualifiers_' collection of the property. You must tell WMI to include these ammended qualifiers if you want to see it. In C#, you can achieve this by simply adding the following line of code:
[wmiClass].Options.UseAmendedQualifiers = true; // where [wmiClass] is the instance of your WMI object...
In script, the fix is just as simple, but it took me forever to figure out how to do it. Most of the docs I found on the internet discussed the 'WBEM_FLAG_USE_AMENDED_QUALIFIERS' flag, but this is only useful when coding in C++. Eventually, I found the 'wbemFlagUseAmendedQualifiers' flag they say to use in script, but what does this flag actually map to so that I can use it in my script?
After roughly two hours of frustration searching the internet for a sample, I was able to generate a working script to get the amended qualifiers using vb script:
wbemFlagUseAmendedQualifiers = 131072
Set oService = GetObject("winmgmts:\root\webadministration")
Set oAppPool = oService.Get("ApplicationPool", wbemFlagUseAmendedQualifiers)
Set oProperty = oAppPool.Properties_("managedPipelineMode")
for each oQualifier in oProperty.Qualifiers_
WScript.Echo "Qualifier: [" & oQualifier.Name & "]"
next
Hopefully, this will have saved you some time...