- PowerToys for Windows 10 and Windows 11 - Mon, Jan 30 2023
- Azure Recovery Services vault: Ironing out the confusion - Fri, Jan 20 2023
- Regex in VSCode - Tue, Jan 17 2023
This is the fifth installment of a multi-part series on Windows PowerShell for Windows systems administrators. To become current with our subject matter, I encourage you to read the four previous articles of this PowerShell tutorial.
As we discussed in a previous entry in this series, learning the syntax of the WMI Query Language (WQL) is tough enough without having the understand the WMI-related PowerShell cmdlets as well. In this essay I will introduce you to the nifty Microsoft PowerShell Scriptomatic utility. By the conclusion of this piece you will be integrating WMI and PowerShell with the best of ‘em!
Let’s get right to work.
Preliminary Terminology
As usual, we need to define our terms. By way of review, recall that Windows Management Instrumentation (WMI) is Microsoft’s implementation of Web-Based Enterprise Management (WBEM), which in turn uses the Common Information Model (CIM) standard to define access methods for computers, networks, applications, and so forth. Think of WMI and WBEM as the next generation of the Simple Network Management Protocol (SNMP).
In WMI, managed system information, including hardware and software-related data, is reported by using schemas. We employ the CIM schemas to access WMI classes, which in turn represent the specific data elements that we wish to query.
A WMI namespace is a subsection of the CIM repository. The most commonly used WMI namespace (and the one we will reference in this tutorial) is named root\CIMV2. The root\CIMV2 namespace ncludes an enormous number of Windows-related classes; lots of rich information in there!
Please see the following sources for a complete list of WMI namespaces and classes:
If you prefer the long way (that is, the manual way) around WMI systems administration, you can leverage the PowerShell Get-WMIObject cmdlet as well as your existing knowledge of WQL syntax to do your work. For instance, issue the following statement from a PowerShell prompt to return a list of all available WMI namespaces on the local system:
PS>Get-WMIObject –namespace “root” –query “SELECT * FROM __Namespace” | Select Name
Listing WMI namespaces from PowerShell
However, if you would prefer a bit of automation in your life with respect to WMI and PowerShell, then look no further than the PowerShell Scriptomatic tool. Read on, friends!
Introducing PoweShell Scriptomatic
Scriptomatic v2 is a GUI utility developed by the Microsoft Scripting Guys and has as its goal the easier creation of WMI scripts for system administration.
Scriptomatic 2.0
As you may or may not be able to tell from Figure 2, the use of Scriptomatic involves the following workflow:
- Select your desired WMI namespace and WMI class. The tool helpfully defaults to root\CIMV2.
- Choose appropriate scripting language and output format. Supported languages are VBScript, Perl, Jscript, and Python, and supported outputs are command prompt, plain text, HTML, Excel, and XML.
- Select the target computer(s) for the script
- Use the toolbar buttons to execute the script immediately, save the script to disk, etc.
Scriptomatic is a pretty awesome utility, isn’t it? However, unless you (a) are already proficient in VBScript or Jscript; or (b) already have the Perl and/or Python interpreters installed on your system, this tool is of limited use. After all, we are budding PowerShell scripters, correct?
Fortunately for us, the Microsoft Scripting Guys authored a PowerShell edition of Scriptomatic. You can’t beat the price, either: both Scriptomatic tools are free for your downloading pleasure!
Scriptomatic PowerShell edition
Note that the workflow for the PowerShell edition of Scriptomatic is essentially identical to that of Scriptomatic V2:
- Select your desired WMI namespace and class
- Specify one or more target computers (comma-separated list; you can load this from an external file)
- Use the Control Pad buttons to specify output options
Scriptomatic PowerShell output
Check out the output in Figure 4; these expressions should look familiar to you if you’ve been keeping up on the content in this series. In this example we have variables and an invocation of the Get-WMIObject PowerShell cmdlet.
Following is a brief summary of the functionality of the Control Pad buttons:
- Run: Executes the current code in a command prompt window
- Save: Enables you to save your work as a .PS1 script file
- Clear Script: Clears the work area
- Refresh Script: Updates the active script to reflect any changes
- Notepad: Opens your work in a new Notepad file
- Open Temp File: Opens a blank file in Notepad
Hey, one more trick for you: Click the third toolbar button (for some inexplicable reason the Microsoft Scripting Guys have not differentiated these button icons!) and click Display Class Properties. Next, from the Control Pad, click Refresh Script. You now can drill into the granular data elements (aka properties) within the selected class. This procedure is shown in Figure 5:
Accessing class properties in Scriptomatic
Conclusion
Alrighty then! By now I think that you have a flying head start at using both WMI and PowerShell in your Windows systems administration work. I hope that you found this article helpful.
In the next installment of this series we will examine how to manage Windows Server 2008 roles and features by using PowerShell. Take care, and thanks for reading.
I am unable to find the tool in the links, please confirm the exact link where the tool is present.
It seems that Scriptomatic 1.0 and 2.0 are no longer available as of April 2016.