PowerShell WMI Wizard

wmiwizard If you are a long time PrimalScript user, you know that it has always had support and wizards for WMI.  The upcoming PrimalScript 2009 adds some new WMI features. But I like to tinker, especially with PowerShell. So I created a simple PowerShell script that creates an expression using Get-WMIObject. Think of it as a PowerShell WMI Wizard script.

I know from my experiences in scripting forums and speaking at conferences, that WMI is still a mystery to many administrators.  Believe it not, PowerShell is even more of a mystery.  I see a lot of people (virtually speaking) who want to use PowerShell and WMI but don’t know where to begin and don’t have time to look through a book. I sympathize.

I used SAPIEN’s free PrimalForms tool to create a Windows form and added PowerShell code to query a remote machine for Win32 classes, which most administrators need to use. When you select a class from the drop down list, you’ll see a help description and a list of all properties for that class. Select a property to see what type it is and a help description. If the property has values, like DriveType in the Win32_LogicalDisk, these values will be displayed as well. Knowing these values makes it easier to add filtering to your query.

I didn’t write any of the help information. It’s all right there in WMI. Classes and properties have something called a qualifier. Think of a qualifier as contributing meta information. Most classes and properties have qualifiers that include helpful and descriptive information.  As you look through the code, you can see how I obtained these details.

To build a command, check all the properties you want to include and then click the Create Command button. This will generate a PowerShell expression.  You can edit it if you want. You can copy it using Ctrl-C. Or you can execute it by clicking the Run It! button. The form will close and the command will be executed in your PowerShell session. The command is saved to a script block variable. $wmiwiz, so that you can re-use it or further modify it.

Sure, there are some things missing you might like to see.  There’s no support for alternate credentials. There’s mechanism to automatically generate a filter, but hey, this is free!  Depending on interest and my schedule these may be items for another day.  Or feel free to make the changes yourself.

Even if you aren’t interested in the WMI stuff, the project offers a demonstration of how to use different Windows form controls like combo boxes, rich text boxes, drop down lists and more.

Let me know what you think!

Download a zip file with the PrimalForm project and completed script from SAPIEN’s Free Tools page here.