PowerShell WMI Explorer Part 1
I made a PowerShell GUI WMI Explorer, to explore WMI from PowerShell in a graphical interface
*Edit* updated the script fixing 2 bugs (see comments)
The WMI Explorer will also provide help information for the WMI classes and about methods and properties available, also it will generate Template PowerShell scripts for callng WMI methods, that can be used as base to create PowerShell scripts calling WMI methods.
This WMI explorer is completely written in PowerShell as a script, no CmdLet or external tools or libraries are used !
It's Script-o-Matic for PowerShell ..... but then on steroids !,
It will not generate scripts to list the properties for WMI classes as Scriptomatic does, because in PowerShell this is to easy to do, so there is no need to generate scripts for this, it's easy enough to do on the fly interactively in the PowerShell Console :
Get-WmiObject win32_share
Get-WmiObject win32_share | Format-List [a-z]*
GWmi win32_share | Format Table Name,Path
The first example will show standard view and properties, second example will show all Properties in a list view (as Scriptomatic does), last will show selected properties in a Table view.
So instead of making scripts to just list propertied it will generate template scripts for calling the Methods of the WMI classes, that you can use a a base and/or example for making the PowerShell script for that task.
In this first part of this series about the PowerShell WMI Explorer, I will show how it looks and the basics to get you started with it for browsing.
in the following parts I will show how to generate and use the PowerShell scripts to do WMI tasks by Using the PowerShell WMI Explorer and also cover more advanced topics as connection settings (alternate credentials , special permissions etc.) and other options.
After downloading the script you can just start it from PowerShell
./WmiBrowser.ps1
It will start empty and the computername defaults to . so if you click Connect it will connect to the local computer and will show the namespaces,
the screen will look like this :
If you select a namespace the first time in the WMI explorer, the classes list does stay empty as the classes are not retrieved yet, as indicated in the statusbar you need to doubleclick the namespace to load the classes.
You will see the statusbar change to :
As the CimV2 namespace has a lot of classes this can take a while, you can also see the Classes counter counting up every 10 classes (in XP this counter will start almost at once, on Vista there is a strange delay before the Classes are retrieved)
This is only needed one time, next time you select the node the classes will show up at once without the need to doubleclick as the classes are cached until the browser is closed.
Note that the Namespace is colored blue in the interface to indicate this
I also added a secondary cache, stored in a global variable as a dataset and that will remain the whole PowerShell Session, so if you close the WMI explorer and start a new instance of the script, the classes do not need to be retrieved again using WMI, but are retrieved from this cache, you will need to doubleclick the namespace and its not as fast as the primary cache but still much faster as to retrieve them again with WMI (especially for remote computers) this cache is populated on a computer by computer base so every computer you connect to will use it's own database.
When all classes are retrieved they will be listed in the Classes window , as you can see the description will popup when you hold the mouse above a class, so you do not need to enlarge the list window to read it.
When you doubleclick the class the Methods and Property lists in the Class view will be filled and the Help for the Selected WMI class will be retrieved.
You can find the help for this Class in RTF format on the first Tabpage of the main view.
Note also that I also changed the layout of the panels in the next screenshot, I did make the NameSpaces panel smaller as I did not need it anymore, and the help (main) window bigger.
you can size the NameSpaces - Classes - Status - and main Panels individually by dragging the splitters between them with the mouse, so that it is easy to customize the view for current task
Instances
Next you can retrieve the instances, By using the "Get Instances" on the Class Panel,this will retrieve all instances of the WMI Class (like get-WmiObject) and fill the DataGrid on the Instances Tab in the Main Panel window with retrieved data :.
You can use the checkboxes in the PropertyList to show or hide columns,
also if you doubleclick on the gray box in front of the WMI Instance, the selected WMI Instances properties will be show as text in a list form (format-list *) in it's own Tabwindow :
This was it for this post, I think I covered the basics needed for browsing and viewing WMI classes with the WMI explorer and to get on your way exploring WMI classes and properties with it on your own
In the next post, I will show how to get the help information and template scripts for a specific method, and I will show how to adapt and configure the scripts generated by the WMI Explorer to change the template scripts into working PowerShell scripts and how use the scripts after that by showing how to adapt and use the generated scripts to:
- Delete a Share using WMI in PowerShell using Template generated by WMI explorer and alternatives
- Create a Share using WMI in PowerShell using Template generated by WMI explorer and alternatives
and also give a bit more background about how these scripts work.
In later posts in this series I will also get into the Workings of the WMI explorer and how the scripts a generated.
* Remark * I will make a Overview Page for the PowerShell WMI explorer script later that always has the latest version, but for the time being posted the script also as an attachment to this post,
I discovered some little glitches while creating the examples for next post , so if you go on your own exploring the WMI explorer and use the generate scripts, I noticed there are still some little bugs in the generated scripts (for example a dot behind the WMI classname in generated script that should not be there), I will update them later, but added the current script already for your convenience so you can start playing with it already, please report back any tips / bugs / problems you might encounter, input would be very helpful in tuning the generating of scripts)
I use this WMI explorer tool a lot, and it really does and did pay off for me finding WMI classes and Methods for a task, and also for creating scripts. (and already did for years in the VB.NET version I made (it did also generate VB.NET code and also could compile it on the fly , biggest advantage of "Old" VB.NET version is that is is completely Multithreading so I can cancel running task, interface is more responsive, and much faster , also it has a couple more tricks (performacecount filtering e.t.v.), but allready the PowerShell script interface is better I think)
For the curious ones, this is how the "old one" that I did in VB.NET ( VS2002 .NET1.0 ) some years ago does look like :
So yes, For a tool like this it might been better to write a application not a script but I really enjoyed the challenge to make it over completely in PowerShell,and that it was possible to build a Tool like this WMI Explorer completely in a PowerShell script (OK I did cheat a but by designing the FormLayout in VS2005 first and translated it to PowerShell, so I could use the Form Designer instead of making it by hand)
I think this WMI explorer is a great tool for discovering and learning WMI in PowerShell , and a very valuable tool for administrators also (It is for me at least, most of my WMI classes and method knowledge comes from this WMI Explorer by using it over the years I think , much less need to search the SDK so timeserver ), so if you try the script I really would look forward to hear what you think about it, so if you download and use the script please leave a comment or send a mail about your impression, thanks ! .
Enjoy,
Greetings /\/\o\/\/