PowerShell WMI Classes

Types of WMI Class in PowerShell

Windows Management Instrumentation (WMI) provides a way of accessing details of your operating system that are normally hidden from the Control Panel, Device manager or Windows Explorer.  Every time I review WMI it amazes me the number and variety of these probes, or WMI Classes that are available to PowerShell’s Get-WmiObect.

Topics for PowerShell WMI Classes

 ♣

PowerShell Tutorial to List WMI Classes

Pre-requisites:  Visit Microsoft’s site and download the correct version of PowerShell for your operating system.

  • Launch PowerShell (Preferably ISE)
  • Copy the lines of code below (into memory)
  • Right-click on the PowerShell symbol
  • Edit –> Paste
  • Press enter to execute the code.

PowerShell Command to Enumerate All WMI Classes

# PowerShell WMI classes
# Author: Guy Thomas

Get-WmiObject -List

Note 1:  As usual, you can view all a PowerShell cmdlets parameters with Get-Help, for example:
Get-Help Get-WmiObject.

To List Every WMI Class Beginning with Win32

Although not all PowerShell cmdlets use the -List parameter, Get-WmiObject does support this handy enumerator.  However, there is a problem with the base command: Get-WmiObject -List, namely the overwhelming number of classes returned.  For this reason I have introduced extra code which filters classes relevant to a particular project; for example, network classes. One of the most useful subsets of WMI classes is the one beginning with Win32.  This example will give you a count of the Win32 classes.

# PowerShell example to list all Win32 WMI classes
# Author: Guy Thomas
# Version 1.4 February 2010 tested on PowerShell v 1.0 and 2.0

Clear-Host
$i=0
$Type = "Win32"
$WMI = Get-WmiObject -List | Where-Object {$_.name -Match $Type}
Foreach ($Class in $WMI) {$Class.name; $i++}
Write-Host ‘These are the ‘ $i’ types of ‘$Type

Learning Points

Note 2:  This script employs 3 variables, $i to count the instances, $Type to hold the string you wish to filter, and $WMI to initiate the loop which counts the object classes.

Note 3:  One side-effect of introducing extra PowerShell techniques is that I have made the script unnecessarily long and complex.  For simplicity, you could strip the script down to this one command:

Get-WmiObject -List | Where-Object {$_.name -Match "Win32"}

Challenge:  Amend my example script to display extra information

Challenge 1:  Observe and trace how PowerShell’s -Match parameter compares the value held by $Type.  Incidentally, you could experiment with "CIM" instead of "Win32".

Challenge 2: Wrap this script in a function to make it more flexible in searching for classes.  See Show-WMI

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

To List Only WMI Network Classes

The additional feature of this script is that refines the search from the broad ‘Win32’, to the narrower ‘Win32_Network’.  The result is a list of network WMI classes.

# PowerShell example to list every WMI class matching Win32_network
# Author: Guy Thomas
# Version 1.5 February 2010 tested on PowerShell v 1.0 and 2.0

Clear-Host
$i=0
$Type = "Win32_network"
$WMI = Get-WmiObject -List | Where-Object {$_.name -Match $Type}
Foreach ($Class in $WMI) {$Class.name; $i++}
Write-Host ‘There are’ $i’ types of ‘$Type

Learning Points

Note 4:  In practical terms, most of the 7 network classes are disappointing.  However, this is a feature of WMI, it sounds exciting to find so many classes, but when it comes down to practicalities, only one or two are truly useful for any given task.

Note 5: You could use the alias PowerShell gwmi instead of Get-WmiObject

See a Review of SolarWinds WMI Monitor »

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

How to Research WMI Properties with Get-Member

Nearly everyone who scripts with PowerShell calls for help with Get-Member.  Some experts freely admit employing this technique, while others pretend that they can memorize all the properties.  (One or two sad cases really can, and consequently, will quote all the Properties of any class you care to name).

I cannot emphasise too strongly how important Get-Member is in mastering PowerShell.  Not only can you apply Get-Member to every other PowerShell cmdlet, but also third-party add-ons such as QAD support this help system.

Clear-Host
Get-WmiObject -class Win32_NetworkAdapterConfiguration | Get-Member

Note 6:  The secret to success with Get-Member is to remember the (|) pipeline symbol before you append this Get-Member cmdlet.

Note 7:  If you are overwhelmed with information you can add the -MemberType parameter with a value of ‘property’ hence: Get-Member -MemberType property [a-z]*.

Note 8:  Before we leave Get-Member a reminder that even this command accepts Get-Help, thus you could try: Get-Help Get-Member -full.  My point is that help will reveal other options, for example -MemberType Method.

Summary of PowerShell WMI Classes

The key information that PowerShell’s Get-WmiObject needs is a WMI class.  The examples on this will help you to research the best class for your task.  Those WMI Classes beginning with Win32 are a particularly rich source, however to refine your search try adding a PowerShell -Match statement.

If you like this page then please share it with your friends

 


See More Microsoft PowerShell WMI Examples:

Home   • PowerShell Get-WmiObject   • Win32_ComputerSystem   • Free WMI Monitor

WMI Class  • [WMI] Type  • Win32_printer   • Win32_product   • SystemRestore   • WMI Services

WMI Disk   • DNS   • Memory  • PowerShell -Filter   • Check Server UpTime   • ConvertToDateTime

Please email me if you have a script examples. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.