#!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";
|