PowerShell for Windows Admins

Apr 7 2014   12:49PM GMT

Finding the class key

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: