PowerShell for Windows Admins

Mar 10 2012   5:44AM GMT

Migrating to CIM-part 2

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

 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.

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: