Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've used Win32::OLE and Win32::OLE::Enum to grab WMI information. As for enumerating your output, what are you trying to accomplish? I'd tackle this differently based on if you were printing a tree menu of the data, or simply reporting on it.

Either way I've included a basic example of grabbing a CPU value from WMI. This script contains more source the necessary, to assist with learning.

#!perl #Change These Variables (Leave all variables BLANK if connecting to lo +cahost)# $server=""; $remote_user=""; $remote_pass=""; use Win32::OLE qw(in with); use Win32::OLE::Enum; Win32::OLE->Option(Warn => 0); ##WMI Connect## $WMI = Win32::OLE->new('WbemScripting.SWbemLocator'); if(!$WMI){ print Win32::OLE->LastError(); exit; } $Services = $WMI->ConnectServer($server, "root/cimv2", $remote_user, $ +remote_pass); if(!$Services){ $err_tmp_raw=Win32::OLE->LastError(); $err_tmp=Win32::OLE->LastError(); $err_tmp=~s/\'/\\'/g; $err_tmp=~s/\"/\\"/g; $err_tmp='Access Denied' if($err_tmp=~m/denied/i); $err_tmp='WMI Not Installed' if($err_tmp=~m/class not registered/i +); $err_tmp='RPC Server Unavailable' if($err_tmp=~m/rpc server is una +vailable/i); print "$err_tmp\n"; print Win32::OLE->LastError(); exit; } my $Processor_set = $Services->InstancesOf("Win32_Processor"); foreach my $object (Win32::OLE::Enum->All($Processor_set)){ print "CPU: $object->{'caption'}\n"; print "CPU Utilization: $object->{'LoadPercentage'}\n"; }

Hope this helps.


In reply to Re: How to Enum windows ActiveDirectory OU objects by FitTrend
in thread How to Enum windows ActiveDirectory OU objects by blackadder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-19 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found