When you want to access a specific WMI instance with PowerShell’s [Wmi] type shortcut, you might at first struggle to determine what properties WMI lets you search on. These properties are called key properties on the class. Example 151 gets all the properties you may use in a WMI filter for a given class.
Example 151. GetWmiClassKeyProperty.ps1
############################################################################## ## ## GetWmiClassKeyProperty.ps1 ## ## Get all of the properties that you may use in a WMI filter for a given class. ## ## ie: ## ## PS >GetWmiClassKeyProperty Win32_Process ## ##############################################################################
param( [WmiClass] $wmiClass )
## WMI classes have properties foreach($currentProperty in $wmiClass.PsBase.Properties) {
## WMI properties have qualifiers to explain more about them foreach($qualifier in $currentProperty.Qualifiers) {
## If it has a 'Key' qualifier, then you may use it in a filter if($qualifier.Name eq "Key") {
$currentProperty.Name } } }