header image

Finding the class key

Posted by: | April 7, 2014 | No Comment |

Time to extend our module for investigating CIM.  This time I want to show you how to find the key to the class.

You need to know the key property of a CIM class when you perform a number of actions – most particularly when you create an instance of the class. Its just a matter of iterating through the properties of the class to find any that have a qualifier called KEY.

function Get-ClassKey {
param (

[string]$namespace = ‘root/cimv2’

$class = Get-CimClass -ClassName $classname -Namespace $namespace

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



The classname parameter is made mandatory and the namespace defaults to root/cimv2

Get the class and then loop through the each property – looking for a qualifier called key.

under: PowerShell and CIM, PowerShell and WMI, PowerShell V3, PowerShell v4