This piece of code displays all the properties (with their values) that are available for a WMI class method. With it, you have to change just 1 parameter in stead off all the properties.

By changing the variables, you can change either the computer, namespace or class method.

I've tested in on an Windows XP SP2 machine, and had no problems so far.

(Thanks to the Microsoft Scripting guys for the vb code)
#!/usr/local/perl use Win32::OLE('in'); use strict; my $stepOk = 1; my $errorMsg = ""; # Variables my $wmiService = ""; my $computer = "."; # Computer to connect to: . = local host my $namespace = "\\root\\cimV2"; # Namespace to connect to my $class = "CIM_Controller"; # Class Method from which you want +to retrieve the properties $wmiService = Win32::OLE->GetObject("winmgmts:\\\\".$computer.$namespa +ce); ($stepOk = 0) unless $wmiService; if(! $stepOk) { $errorMsg = "Unable to open wmi services"; print $errorMsg."\n"; } else { my $subDevices = $wmiService->ExecQuery("Select * from ".$class); print "***********************************************\n"; foreach my $subDevProp ( in( $subDevices ) ) { foreach my $prop (in($subDevProp->{Properties_})) { print "***** ".$prop->{Name}.": ".$prop->{Value}."\n"; } print "*********************************************\n"; } } # Scripted by jschollen # Thanks to the Microsoft Scripting Guys

Replies are listed 'Best First'.
Re: WMI: display Class properties
by Posthumous (Scribe) on Nov 07, 2006 at 20:23 UTC
    Thanks for posting these. They make a handy reference. I did modify the wmi query a bit so it goes to look for specific information, rather than just dumping everything available. I'm posting this as a further example to help others. The only changes necessary are what gets assigned to the $class variable and:
    else { #look for network printers (Attributes not 64) my $subDevices = $wmiService->ExecQuery("Select DeviceID from ".$c +lass." WHERE Attributes != 64"); print "*********$computer**********\n"; foreach my $subDevProp ( in( $subDevices ) ) { foreach my $prop (in($subDevProp->{Properties_})) { print"$prop->{Name}\: $prop->{Value}\n"; } } }