WMI Reference for PowerShell

The most complete WMI Reference for PowerShell

Windows Management Instrumentation (WMI) is a framework for managing Windows-based operating systems. WMI supplies management data to other parts of the operating system and products, for example SCOM (System Center Operations Manager).

PowerShell can directly access WMI, so you can write scripts on your own to query hardware components, check system health, or automate configuration. This can be as easy as writing one line of PowerShell code.

Listing all Network Shares
# list all shared network drives:
Get-CimInstance -ClassName Win32_Share

This reference provides you with the most complete PowerShell reference for WMI, plenty of ready-to-use PowerShell code examples, and many tutorials.

WMI Classes

At the core of WMI are the WMI Classes. Each class represents a given entity. In the example above, the class Win32_Share describes a network share, and each real network share is represented by an Instance of the class.

Get-CimInstance is one of the built-in PowerShell WMI commands: it takes a class name and returns all available class instances.

Discovering WMI Class Names

The first important step in learning how to leverage WMI is: what are the names of available WMI Classes? Once you discover, for example, that disk drives are represented by the WMI class Win32_LogicalDisk, you can use the very same command Get-CimInstance from the previous example to get a list of drives including all kinds of useful configuration data instead.

Listing all Disk Drives
# get all disk drives:
Get-CimInstance -ClassName Win32_LogicalDisk

# view all properties:
Get-CimInstance -ClassName Win32_LogicalDisk | Select-Object -Property *

# view a custom selection of properties:
Get-CimInstance -ClassName Win32_LogicalDisk | 
	Select-Object -Property DeviceID, Description, Size, FileSystem

The result looks similar to this:

DeviceID Description               Size FileSystem
-------- -----------               ---- ----------
C:       Local Fixed Disk 1007210721280 NTFS
D:       CD-ROM Disc         3549376512 UDF

So knowing the names of WMI Classes is key. Let’s find out the valid class names next.

WMI Namespaces

There are thousands of WMI Classes, and 3rd party can add their own. To keep things organized, WMI uses a hierarchical Namespace. It works pretty much like folders in a file system: all classes with a common objective are stored in the same “folder”.

Discovering Classes via PowerShell Code

PowerShell can dump the WMI Namespace for you.

Once you know the names of the WMI “folders”, PowerShell can also dump the class names inside of each.

Listing Useful WMI Classes in the Default Namespace

You really should take the time and read more about Namespaces and Classes, but if you are in a hurry, here is a script that lists potentially useful WMI Class Names in the default namespace root/cimv2:

# get all classes from namespace "root/cimv2"...
Get-CimClass -Namespace 'root\cimv2' |
  # exclude classes that start with __/CIM/Win32_PnP/Win32_Perf
  Where-Object CimClassName -NotMatch '^(__|CIM_|Win32_PnP|Win32_Perf)' |
  # exclude classes with less than 4 properties...
  Where-Object { $_.CimClassProperties.Count -gt 3 } |
  # return just the class name...
  Select-Object -ExpandProperty CimClassName |
  # sort results:
  Sort-Object

Discovering Classes in this Reference

This reference provides you with rich documentation and describes each WMI Class in great detail. To find out WMI Class Names, click one of the Namespaces listed in the left navigation bar. Start with the default namespace root\cimv2.

This opens a page with a list of all WMI Classes organized in the namespace, plus a quick description of what the class represents.

Click any class to get detailed information about the class, including plenty of read-to-use PowerShell examples. Win32_BIOS for example represents the computer bios and is a good place to start.

WMI Provider

Each class is implemented by a WMI Provider. Some providers just implement a few classes while other providers implement hundreds or even thousands.

In the left navigation bar, below the namespaces, you find a list of providers that typically ship with Windows operating systems. Click on a provider in the list to learn more about it, and view the classes it implements.

When you look at classes from the Provider perspective, you can quickly find all WMI Classes that deal with the same topic.