Understanding the Windows Management Instrumentation (WMI) Part II

This is part II for the introduction to Windows Management Instrumentation. In this tutorial you will learn how to make PowerShell interact with WMI.

Setup

If you have not already done so, click open Windows PowerShell ISE.

The Concept:

Working in PowerShell in collaboration with WMI is quite simple. The Cmdlet that makes this possible is the Get-WMIObject Cmdlet. Once you give Get-WMIObject the name of a class, it outputs all the information about the instances of the particular class.

Step one.

There are many things you can check out, such as your BIOS (firmware interface of PC motherboards). To check your system BIOS, run the following command:

Pre

Get-WMIObject Win32_BIOS

Pre

Now to get far more general information of your computer system, the following command will be of more use:

Example

    Get-WMIObject Win32_ComputerSystem

Copy and Try it

The first command will have listed the BIOS version, manufacturer, computer name as well as the serial number and version ID’s. The second command will have listed the domain, manufacturer, model, name, primary owner name and the total physical memory.
The output will result like the image below:

Step two.

With WMI, you can also query the same exact BIOS information remotely, by using the WMIObject Cmdlet’s -computername parameter, as demonstrated below:

Example

    Get-WMIObject Win32_BIOS â€"computername PCNAME

Copy and Try it

The resulting output from running the command should appear like the image below:

Step three.

There are multiple classes in WMI that are at our disposal at any time. A majority of the time, we will only be dealing with core WMI classes that directly interact with various Windows or system components. You can get a list of these classes by entering the following the command:

Example

    Get-WMIObject list

Copy and Try it

The image below is the full list of available WMI classes:

Or you can use pipelines to filter them to present exactly what you want. Say, you want the classes that start with Win32_, you would enter the following command:

Example

    Get-WMIObject list | where {$_.name.startswith(Win32_)}
    

Copy and Try it

One thing to keep in mind is that there is a class available for just about any part possibly made of Windows. Items such as the BIOS, ComputerSystem, Directory, Environment, NetworkAdapter, PrintJob, Printer, Processor and many others are within this list. You can even query a class outside of a namespace, you simply have to explicitly define it using the â€"namespace parameter.
Say for example you want to query the IISWebService class of root\MicrosoftIISV2, you would run the following:

Example


    Get-WMIObject IISWebService namespace root\MicrosoftIISV2

    

Copy and Try it

By doing this, you will now see all the properties available to you and not just what is returned by default.

Remarks last but not least:

WMI is quite a powerful administrative feature. You can even combine it with SQL to get WQL, but we discuss this in another tutorial. Join us next time for additional Windows PowerShell tutorials! Till then.