PowerTip: Use PowerShell to Find Key of WMI Class

PowerTip: Use PowerShell to Find Key of WMI Class

  • Comments 1
  • Likes

Summary: Use Windows PowerShell to find the key of a WMI class.

Hey, Scripting Guy! Question How can I use Windows PowerShell to discover the property that has the key qualifier for a WMI class?  

Hey, Scripting Guy! Answer Use Get-CimClass and iterate through the properties:

$class = Get-CimClass -ClassName Win32_Process

foreach ($property in $class.CimClassProperties) {

 $property | select -ExpandProperty Qualifiers |

 foreach {

   if ($_.Name -eq 'key'){

     $property

   }

 }

 }

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • We can also use a non-linear one-liner:

    Get-CimClass -ClassName Win32_Process |

        select -expand CimClassProperties |

        where{$_.QUalifiers['Key']}

    How is that for a dashing example?