Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Physical memory on remote machine

by mjg (Beadle)
on Mar 27, 2006 at 23:19 UTC ( #539578=sourcecode: print w/ replies, xml ) Need Help??

Category: NT Admin
Author/Contact Info Mark Gardner
Description: A short example of WMI and Win32::OLE to get info from another server. Note that the hostname needs to be laundered or Win32::OLE will cry.
#!perl -wT

use Win32::OLE qw(in);
use Regexp::Common;

my $hostname = shift @ARGV || '.';
my $locator = Win32::OLE->new('WbemScripting.SWbemLocator')
  or die "Cannot access local WMI locator: ", Win32::OLE->LastError;

if ($hostname =~ /^$RE{net}{domain}{-keep}$/) {
    $hostname = $1;
} else {
    die "$hostname has insecure data, can't continue";
}
my $services = $locator->ConnectServer($hostname, 'root/cimv2')
  or die "Cannot access remote WMI services: ", Win32::OLE->LastError;

my $memory = 0;
$memory += $_->{Capacity} foreach in
  $services->ExecQuery("select * from Win32_PhysicalMemory");
print "$hostname has ", $memory/1024/1024/1024, " GiB\n";

Comment on Physical memory on remote machine
Download Code

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://539578]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-08-28 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (263 votes), past polls