Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



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:  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 1:  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 2:  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:  Observe and trace how PowerShell's -match parameter compares the value held by $Type.  Incidentally, you could experiment with "CIM" instead of "Win32".

Guy Recommends: WMI Monitor and It's Free!Solarwinds Free WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft 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.

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 1:  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 3: You could use the alias PowerShell gwmi instead of Get-WmiObject

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 1:  The secret to success with Get-Member is to remember the (|) pipeline symbol before you append this Get-Member cmdlet.

Note 2:  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 3:  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   • WMI Services   • Win32_ComputerSystem

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

WMI Disk   • DNS   • PowerShell -Filter   • Windows PowerShell   • Memory

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.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Guy Recommends: WMI Monitor and It's Free!Solarwinds WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

Home Copyright © 1999-2012 Computer Performance LTD All rights reserved

Please report a broken link, or an error.