- How to create a PowerShell alias - Tue, Jul 29 2014
- System Center Updates Publisher – Create a SCUP catalog - Fri, May 23 2014
- System Center Updates Publisher – Third-party patch management - Wed, May 21 2014
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 = "."
Set WshShell = WScript.CreateObject("WScript.Shell")
strQuery="SELECT * from Win32_ComputerSystem"
Set col=GetObject("WinMgmts://" & strComputer & "/root/cimv2").ExecQuery(strQuery)
For Each WMIProperty in col
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:
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.
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.
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.