Categories

Finding the class key

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 {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[Alias("Class")]
[ValidateNotNullOrEmpty()]
[string]$classname,

[ValidateNotNullOrEmpty()]
[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'){
     $property
   }
}

}

}

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>