This is part II for the introduction to Windows Management Instrumentation. In this tutorial you will learn how to make PowerShell interact with WMI.
If you have not already done so, click open Windows PowerShell ISE.
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.
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:
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:
With WMI, you can also query the same exact BIOS information remotely, by using the WMIObject Cmdlet’s -computername parameter, as demonstrated below:
The resulting output from running the command should appear like the image below:
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:
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:
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:
By doing this, you will now see all the properties available to you and not just what is returned by default.
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.