Improving CIM/WMI method discovery

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

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

Leave a Reply

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

You are commenting using your 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