Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

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\/\/

Published Thursday, March 22, 2007 5:00 PM by admin
Attachment(s): WmiExplorer.zip

Comments

# re: PowerShell WMI Explorer Part 1

MOW, as always a tremendous job.

Thanks!

panderon

(Sami)

Thursday, March 22, 2007 6:13 PM by Panderon

# re: PowerShell WMI Explorer Part 1

@ panderon

thanks, glad you like it

enjoy

Greetings /\/\o\/\/

Thursday, March 22, 2007 6:45 PM by MoW

# re: PowerShell WMI Explorer Part 1

I downloaded the attachment and tried running it.  

I got the following error:

Unable to find type [Drawing.Color]: make sure that the assembly containing this type is loaded.

At C:\dev\ps\WmiExplorer.ps1:757 char:40

+ Function Set-StatusBar ([Drawing.Color]$ <<<< Color,$Text) {

I thought System namespace is already loaded into PS runtime.

Thursday, March 22, 2007 8:00 PM by Roman

# re: PowerShell WMI Explorer Part 1

Hello,

i found following bug by executing the script:

Der Typ [Drawing.Color] kann nicht gefunden werden: Stellen Sie sicher, dass die Assembly, die diesen Typ enthält, gela

den wird.

Bei C:\PoSh\WmiExplorer\WmiExplorer.ps1:758 Zeichen:40

+ Function Set-StatusBar ([Drawing.Color]$ <<<< Color,$Text) {

Can you tell me what´s wrong and what i can do for it

Thursday, March 22, 2007 8:34 PM by Robert

# re: PowerShell WMI Explorer Part 1

So _this_ is why you've been so quiet. Nice job!

Thursday, March 22, 2007 9:24 PM by Joe

# re: PowerShell WMI Explorer Part 1

I am getting following error. Any idea how to rectify it.

Unable to find type [Drawing.Color]: make sure that the assembly containing this type is loaded.

At E:\Tech\PowerShell\WmiExplorer.ps1:757 char:40

+ Function Set-StatusBar ([Drawing.Color]$ <<<< Color,$Text) {

- Nikhil

Friday, March 23, 2007 1:44 AM by nikhilbhandari

# re: PowerShell WMI Explorer Part 1

sorry, I forgot to load a .NET library,

You also need to load the System.Drawing assembly, you can run this line before starting the explorer:

[void][reflection.assembly]::LoadWithPartialName("System.Drawing")

Sorry was in my profile, will fix this for next post

Greetings /\/\o\/\/

Friday, March 23, 2007 6:36 AM by MoW

# re: PowerShell WMI Explorer Part 1

But even after adding line to the script, I am getting the same error.

Friday, March 23, 2007 9:30 AM by nikhilbhandari

# re: PowerShell WMI Explorer Part 1

I think instead of [Drawing.Color]$Color, it should only be $Color.

Friday, March 23, 2007 9:36 AM by nikhilbhandari

# re: PowerShell WMI Explorer Part 1

I tried to run this and I get an error

+ Function Set-StatusBar ([Drawing.Color]$ <<<< Color,$Text) {

Not sure why I get this but I am anxious to get it working.

Friday, March 23, 2007 10:13 AM by Johnny Costello

# re: PowerShell WMI Explorer Part 1

I updated the Script with the 2 fixes,

[void][reflection.assembly]::LoadWithPartialName("System.Drawing")

and as the assembly is loaded in the script, I needed to remove the [Drawing.Color] (not needed when loaded before start of script )

[Drawing.Color]$Color, changed to only :

$Color

now it should work.

Thanks for the input.

Greetings /\/\o\/\/

Friday, March 23, 2007 12:00 PM by MoW

# re: PowerShell WMI Explorer Part 1

Very slick. I haven't look at the script itself yet, but the next thing to add would be support for alternate credentials.

Friday, March 23, 2007 2:14 PM by Jeff Hicks

# Adminspotting.net &raquo; Links for March 23, 2007

Friday, March 23, 2007 10:00 PM by Adminspotting.net » Links for March 23, 2007

# re: PowerShell WMI Explorer Part 1

@ Jeff,

thanks,

> the next thing to add would be support for alternate credentials.

Try to doubleclick the servername in the status panel ;-)

More in later posts.

Greetings /\/\o\/\/

Saturday, March 24, 2007 4:48 AM by MoW

# WMI Explorer

Yeah yeah I hear you say I can use Scriptomatic so what is new .. Well Marc aka MOW aka the PowerShell

Monday, March 26, 2007 5:41 AM by Carpe Diem: Flaphead.com @ Home

# PowerShell WMI Explorer Part 2

In the first part of this series : PowerShell WMI Explorer Part 1 we used the browser to explore the

Monday, March 26, 2007 3:29 PM by The PowerShell Guy

# re: PowerShell WMI Explorer Part 1

Sorry no URL; question; what permissions are needed to connect this .ps1 to my Domain Controler?

I get access denied when I try to connect?

TIA

Friday, March 30, 2007 7:15 PM by Derik

# re: PowerShell WMI Explorer Part 1

I am getting this error:

Unable to find type [wmisearcher]: make sure that the assembly containing this type is loaded.

Property 'Text' cannot be found on this object; make sure it exists and is settable.

At C:\Tools\WmiExplorer.ps1:1416 char:30

+ trap {Write-Host $_ ;$status.T <<<< ext = "unexpected error";$slMessage.Text = "$_.message";continue}

Any suggestion on how to fix it?

Thursday, April 05, 2007 1:57 PM by Pavel

# re: PowerShell WMI Explorer Part 1

@ Pavel,

Are you sure you are on PowerShell 1.0 RTM ?

This as the WMI adapter has changes since earlier beta,s

Greetings /\/\o\/\/

Friday, April 06, 2007 10:15 AM by MoW

# re: PowerShell WMI Explorer Part 1

Wow!  Impressive!  Nice job!

Thursday, May 03, 2007 3:22 PM by Michael

# re: PowerShell WMI Explorer Part 1

thanks much for your book and this script

though i'd pass along this from a real newbee

after unziping the file i had to right click on it and unlock it and of course

Set-ExecutionPolicy remotesigned

thought i was really cool remembering the Set-ExecutionPolicy  then got hosed by the file being locked got the

\WmiExplorer.ps1 is not digitally signed. error and had to think about it for a min or 2

Thursday, June 14, 2007 10:35 PM by mike mccafferty

# re: PowerShell WMI Explorer Part 1

So much wonderful!!!!

I've use wmi for some time, and it always make me sick. Now, it seems that only your WMI Explorer can cure me.

You are so much cool!

millions thanks!!

Monday, August 20, 2007 1:15 AM by Luoyi

# re: PowerShell WMI Explorer Part 1

Thanks much!

I was trying to work on presenting WMI info via tabbed pages using Powershell and I found this.

Great stuff!!

Keep at it!!

Tuesday, August 21, 2007 3:06 AM by titovic

# re: PowerShell WMI Explorer Part 1

@ titovic, thanks for leaving a positive comment

glad you found it usefull

Greetings /\/\o\/\/

Tuesday, August 21, 2007 3:23 PM by MoW

# re: PowerShell WMI Explorer Part 1

You can skip the step of translating your form to PowerShell now-- there is a PowerShell script form desinger available now which has the added benefit of letting you open the for again later for editing: http://www.scriptformdesigner.com

Tuesday, September 25, 2007 11:43 PM by Joe

# re: PowerShell WMI Explorer Part 1

The file D:\Scripts\WmiExplorer.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details..

At line:1 char:17

I issued a set-execution-policy remotesign etc.. but no luck..

thks..

Saturday, September 29, 2007 7:40 PM by Payne

# re: PowerShell WMI Explorer Part 1

Payne,

Rightclick the file in internet explorer choose properties and unblock .

Greetings /\/\o\/\/

Monday, October 01, 2007 11:03 AM by MoW

# re: PowerShell WMI Explorer Part 1

Unblock worked!!!

WOW!...great tool and great job!

Thanks

Thursday, October 04, 2007 9:33 AM by Payne

# PowerShell GUI forms Editor and new PodCast

As I was kind of busy last week so a bit late but very interesting PowerShell News. PowerScripting Podcast

Saturday, October 06, 2007 6:20 AM by The PowerShell Guy

# PowerShell Plus 和 PowerShell WMI Browser

PowerShell Plus 和 PowerShell WMI Browser

Monday, October 08, 2007 7:33 AM by Edengundam

# re: PowerShell WMI Explorer Part 1

Is their a way to add credentials.  I'm having problems connecting to certain servers.  Also, any way of exporting the data versus copy/paste?  Thanks!

Dee

deepakm@rice.edu

Tuesday, March 04, 2008 11:44 AM by dee

# re: PowerShell WMI Explorer Part 1

Dee,

There is a Bug in PowerShell V 1.0 with alternate credentials, hence I removed the Username  password for this version

(you can set username by doubleclicking Connection, but I show now credentials box as it does not work anyway in V1 )

For V2 of PowerShell this will work

Greetings /\/\o\/\/

Tuesday, March 04, 2008 6:19 PM by MoW

# re: PowerShell WMI Explorer Part 1

thanks.  i've uninstalled v1 and installed v2.  Where do I doubleclick Connection.  I don't see that.  I tried doubleclicking "Connect", but nothing.  I look forward to your prompt resolution.  thank you again!  :)

Dee

Wednesday, March 05, 2008 9:20 AM by dee

# re: PowerShell WMI Explorer Part 1

also, know of a way to create a output of a list of server's running services and scheduled tasks...  any help would be greatly appreciated.  I'm new to powershell.  thanks!

Dee

Wednesday, March 05, 2008 9:24 AM by dee

# The PowerShell Guy : PowerShell WMI explorer update for PowerShell V2 CTP

# re: PowerShell WMI Explorer Part 1

Wednesday, March 05, 2008 5:39 PM by MoW

# WMI를 통한 Hyper-V 관리...

많은 세미나에서 제가 Windows Server 2008 Hyper-V에 대한 관리를 WMI 를 통해서 가능하다라고 많이 말씀드렸습니다. WMI는 Windows에 대한 전반적인 정보

Sunday, March 30, 2008 9:58 PM by 꼬알라의 하얀집...

# BSonPosh &raquo; Citrix License Info (using WMI)

Thursday, May 08, 2008 1:20 PM by BSonPosh » Citrix License Info (using WMI)

# WMI Classes

In this post http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!1525.entry I talked about

Saturday, July 26, 2008 8:22 PM by Richard Siddaway's Blog

# Network Error Statistics | keyongtech

Thursday, January 22, 2009 2:04 AM by Network Error Statistics | keyongtech

# Discovering WMI

One thing that seems to come up rather frequently on the newsgroups is what WMI class do I need to use

Thursday, February 19, 2009 3:24 PM by Richard Siddaway's Blog

# PowerShell and WMI namespaces

When I wrote my previous blog post about blogging, I remembered how much of a sucker for the concept

Tuesday, May 19, 2009 10:18 PM by Tim Benninghoff

# ????, ?????? ?????????? ?????????? ??????????. &raquo; PowerShell WMI Explorer Part 1

Anonymous comments are disabled