PowerShell for Windows Admins

Mar 27 2014   2:49PM GMT

Improving CIM/WMI method discovery

Richard Siddaway Richard Siddaway Profile: Richard Siddaway


I recently showed how to create a function that could be used to simplify the use of Get-CimClass.

In this version I’ve added some features:

– parameter validation

– namespace

– try-catch round getting the class information.

This turns the code into:

function Get-CimMethod {


param (






[string]$namespace = ‘root/cimv2’,







$class = Get-CimClass -Namespace $namespace -ClassName $classname -ErrorAction Stop




Throw “Class: $classname NOT FOUND”


if ($methodname)









The module and function can be used like this:

Import-Module CimInvestigation -Force

Get-Command -Module CimInvestigation

Get-CimMethod -classname Win32_Process

Get-CimMethod -classname Win32_Process -methodname Create

Get-CimMethod -classname Win32_Process -methodname Create -namespace root/cimv2

 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: