Categories

Find the key of a WMI class

At least one property of a WMI class will be marked as a key. This information is held in the property Qualifiers which is a collection of data.  The key is needed if you need to create an instance of the class. I’ve shown how to find the key with Get-WmiObject before but not with the new CIM cmdlets.

Its actually easier with the CIM cmdlets

$class = Get-CimClass -ClassName Win32_Process

foreach ($property in $class.CimClassProperties) {
 
$property | select -ExpandProperty Qualifiers |
foreach {
   if ($_.Name -eq 'key'){
     $property
   }
}

}

Get the CIM class. Iterate over the properties and expand the Qualifiers of the property.  Check the names of the qualifiers for key & when you find it print out the property data

Leave a Reply