PoshCode Archive  Artifact [3b79577a67]

Artifact 3b79577a67ee576c29d640992365ce48749e9a84a9298d3618e704c1f2c420d7:

  • File Get-WmiClassKeyProperty.ps1 — part of check-in [d81d875030] at 2018-06-10 13:06:19 on branch trunk — From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes (user: Lee Holmes size: 1286)

# encoding: ascii
# api: powershell
# title: Get-WmiClassKeyProperty.
# description: From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes
# version: 0.1
# type: class
# author: Lee Holmes
# license: CC0
# x-poshcode-id: 2169
# x-archived: 2016-03-18T21:45:15
# x-published: 2011-09-09T21:41:00
#
#
##############################################################################
##
## Get-WmiClassKeyProperty
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################

<#

.SYNOPSIS

Get all of the properties that you may use in a WMI filter for a given class.

.EXAMPLE

Get-WmiClassKeyProperty Win32_Process
Handle

#>

param(
    ## The WMI class to examine
    [WmiClass] $WmiClass
)

Set-StrictMode -Version Latest

## WMI classes have properties
foreach($currentProperty in $wmiClass.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
        }
    }
}