Migrating to CIM-part 2

We need to find the parameters associated with a WMI method – this information has to include the parameter and data type.  WMI also gives a name to the output variable – this becomes a property on the return object.

function get-CIMmethod {            
param (            
$r = Get-CimClass -Namespace $namespace -ClassName $classname             
if ($methodname) {            
 $r.CimClassMethods | where Name -eq $methodname |            
 foreach {            
    $_ | select -ExpandProperty Parameters | Format-Table -Wrap            
else {            

For this task we use Get-CimClass. Think of it as Get-WmiObject –List but with more bells and whistles.

The parameters are a namespace, and class name and an optional method name

The object representing the class information is put into a variable $r

If we don’t specify  a method name we get a summary listing of all methods.

If we do specify a method name we get the summary of the method and an expanded view of the parameters that includes name, type and whether its input (IN) or output (OUT)

Name            CimType Qualifiers
—-            ——- ———-
hDefKey          UInt32 {ID, IN}
sSubKeyName      String {ID, IN}
sNames      StringArray {ID, out}

The other point to note in this function is the simplified where-object syntax. Normally we would use

where {$_.Name –eq $methodname}

but in PowerShell v3 we can simplify to

where Name –eq $methodname

This entry was posted in PowerShell and WMI, PowerShell V3. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s