Accessing a WMI qualifier

A qualifier is a tag that provides more information about a WMI object, method, or property. At times, you may need to access the data stored in a qualifier. For example, a common task is to determine if a provider implements a method by attempting to retrieve the Implemented qualifier for that method. For more information, see WMI Qualifiers and Adding a Qualifier.

You can retrieve the qualifiers on a WMI object in PowerShell by first retrieving the object, and then examining the qualifiers as you would any other property.

To retrieve a qualifier using PowerShell

  • Retrieve the object whose qualifiers you want to view using Get-WmiObject, and then access the qualifiers through the Qualifiers property:

    $myDisk = get-wmiObject Win32_LogicalDisk
    $myDisk.qualifiers
    
    #or
    
    get-wmiObject Win32_LogicalDisk | format-list qualifiers
    
    #or
    
    $myDisk = get-wmiObject Win32_LogicalDisk
    foreach ($qual in $myDisk.Qualifiers)
    { $qual }
    

    For more information, see Retrieving a WMI Instance.

You can retrieve the qualifiers on a WMI instance in C# by first retrieving the object, and then examining the qualifiers as a collection.

To retrieve a qualifier using C# (Microsoft.System.Management)

  1. Retrieve the class whose qualifiers you want to view by creating a CimInstance object, using the specified class name and namespace.

    using Microsoft.Management.Infrastructure;
    ...
    CimSession mySession = CimSession.Create("localhost");
    CimInstance diskDrive = new CimInstance(className, Namespace);
    diskDrive.CimInstanceProperties.Add(CimProperty.Create("DeviceID", "C:", CimFlags.Key));
    CimInstance myDrive = mySession.GetInstance(Namespace, diskDrive);
    

    For more information, see Retrieving a WMI Instance.

  2. You can retrieve the class qualifiers from the CimInstance.CimClass.CimClassQualifiers, the property qualifiers from CimInstance.CimClass.CimClassProperties, and the method qualifiers from CimInstance.CimClass.CimClassMethods.

    Console.WriteLine("Class: " + myDrive.ToString());
    foreach (CimQualifier qualifier in myDrive.CimClass.CimClassQualifiers)
    {
       Console.WriteLine("     " + qualifier.Name.ToString() + ": " + qualifier.Value.ToString());
    }
    
    foreach (CimPropertyDeclaration property in myDrive.CimClass.CimClassProperties)
    {
       Console.WriteLine(property.Name.ToString());
       foreach (CimQualifier qualifier in property.Qualifiers)
       {
          Console.WriteLine("     " + qualifier.Name.ToString() + ": " + qualifier.Value.ToString());
       }
    }
    
    foreach (CimMethodDeclaration method in myDrive.CimClass.CimClassMethods)
    {
       Console.WriteLine(method.Name.ToString());
       foreach (CimQualifier qualifier in method.Qualifiers)
       {
          Console.WriteLine("     " + qualifier.Name.ToString() + ": " + qualifier.Value.ToString());
       }
    }
    

    For more information, see Retrieving a WMI Instance.

You can retrieve the qualifiers on a WMI object in C# by first retrieving the object, and then examining the qualifiers as a collection.

Note

System.Management was the original .NET namespace used to access WMI; however, the APIs in this namespace generally are slower and do not scale as well relative to their more modern Microsoft.Management.Infrastructure counterparts.

 

To retrieve a qualifier using C# (System.Management)

  1. Retrieve the object whose qualifiers you want to view using ManagementObject.

    using System.Management;
    ...
    ManagementObject myDisk = new ManagementObject("Win32_LogicalDisk.DeviceID='C:'");
    

    For more information, see Retrieving a WMI Instance.

  2. Place the qualifiers into a QualifierDataCollection, and enumerate through the QualifierData values.

    
    QualifierDataCollection myQualifiers = myDisk.Qualifiers;
    foreach (QualifierData qd in myQualifiers)
    {
       Console.WriteLine(qd.Name + ": " + qd.Value);
    }
    Console.ReadLine();
    

    For more information, see Retrieving a WMI Instance.

The following procedure describes how to retrieve a qualifier using VBScript.

To retrieve a qualifier using VBScript

  1. Retrieve the object whose qualifiers you want to view, as shown in the following example:

    Set Process = GetObject("winmgmts:Win32_Process")
    

    The most common way to retrieve an object is by using the GetObject method. For more information, see Retrieving a WMI Instance.

  2. Access the qualifiers of the object through the SWbemObject.Qualifiers_ property, as shown in the following example:

    for each Qualifier in Process.Qualifiers_
        WScript.Echo " " & Qualifier.Name
    next
    

The following code example describes how to access all the qualifiers on a Win32_Process object.

On Error Resume Next
Set Process = GetObject("winmgmts:Win32_Process")
WScript.Echo ""
WScript.Echo "Class name is", Process.Path_.Class

'Get the qualifiers
WScript.Echo ""
WScript.Echo "Qualifiers:"
WScript.Echo ""
for each Qualifier in Process.Qualifiers_
    WScript.Echo " " & Qualifier.Name
next

if Err <> 0 Then
    WScript.Echo Err.Description
    Err.Clear
End if

The following procedure describes how to retrieve a qualifier using C++.

To retrieve a qualifier using C++

  1. Retrieve the object whose qualifiers you want to view.

    The most common way to retrieve an object is by using a call to GetObject or GetObjectAsync. For more information, see Retrieving WMI Class or Instance Data.

  2. Retrieve the qualifier set for a given property with a call to IWbemClassObject::GetPropertyQualifierSet or IWbemClassObject::GetMethodQualifierSet methods.

  3. Access the qualifiers of the object through the returned IWbemQualifierSet interface.