This is part two of a three part series of articles covering two great WMI tools, the first tool being Microsoft's free WMI Code Creator.

Mike Taylor

Mike Taylor has been working in IT for 12 years. He is a Windows administrator, scripter and OS deployment engineer based in London.

WMI Code Creator is a tiny (300KB) Microsoft tool available here. To demonstrate its features, the code snippet below is for querying a machine’s model and gives us enough info to start using the tool.
strComputer = "."<br />Set WshShell = WScript.CreateObject("WScript.Shell")<br />strQuery="SELECT * from Win32_ComputerSystem"<br />Set col=GetObject("WinMgmts://" & strComputer & "/root/cimv2").ExecQuery(strQuery)<br />For Each WMIProperty in col<br />PCModel = WMIProperty.Model

First, I need to select the CIMV2 namespace and then find the win32_computersystem class in the class drop-down box. Without reference to a huge book or the internet, you would struggle to discover the properties in the class without perhaps writing a script. Code creator makes this trivial, with the click of a single button which lists all properties. The model is just one property of many, as you can see in figure 2 below:

Free WMI tool WMI creator - Browsing namespace

WMI Code creator showing model

I’ve clicked all three buttons on the tab simply to show you what else the tool gives you. As you can see you can use this class to write a script to join the domain, or you can do less work at let Code Creator live up to its name and write it for you, using the “Execute a method” tab. One minor feature is that the script does not appear in the right hand window until you highlight the instance, as in figure 3.

Free WMI tool WMI creator - Methods

Choosing a method and generating the code

The final feature of code creator is its ability to create code to query explicit properties. You can get as many or as few of the properties as you like by control-clicking each one you want. Again the script generates on the fly on the right pane, in the next figure.

Free WMI tool WMI creator - Properties

Selecting multiple properties and generating more code

As you can see Code Creator even saves you the trouble of using copy and paste with the “open in notepad” button!

Returning to the OS deployment task example, I later found I needed a full script to check certain BIOS values on the HP hardware. Browsing through Code Creator I found Win32_BIOS. This gave plenty of information, but then someone asked to change the boot order in the BIOS. As the Win32_BIOS class has no methods at all, it meant looking deeper. HP has designed a whole new namespace, “root/HP/InstrumentedBIOS” that provides access to altering various BIOS settings from within Windows. This complication called for some experimentation that Code Creator does not have – real-time custom queries. The solution is WMI explorer.

Are you an IT pro? Apply for membership!

1+
Share
0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2019

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account