Skip to content

Instantly share code, notes, and snippets.

@keedi
Forked from aero/remote_wmi.pl
Created April 25, 2013 06:59
Show Gist options
  • Save keedi/5458004 to your computer and use it in GitHub Desktop.
Save keedi/5458004 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
#How to use
#> perl remote_wmi.pl hostname Win32_ComputerSystem
#> perl remote_wmi.pl hostname Win32_PerfFormattedData_PerfOS_System | findstr SystemUpTime
# Here's a list of a few Helpful classes to get you started.
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa394084%28v=vs.85%29.aspx
# Win32_ComputerSystem
# Win32_Processor
# Win32_TimeZone
# ...
use 5.010;
use strict;
use warnings;
use Win32::OLE qw/in/;
my ($strComputer, $strWin32_class) = @ARGV;
my $objWMIService = Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate,(security)}//$strComputer");
my $computers = $objWMIService->ExecQuery("SELECT * FROM $strWin32_class");
if (scalar(in($computers)) lt "1" ) {
say "Check the hostname and class name. No info was found on the specified class.";
exit 0;
}
foreach my $pc ( in($computers) ) {
foreach my $object ( in($pc->{Properties_}) ) {
if ( ref($object->{Value}) eq "ARRAY") {
print " $object->{Name} = { ";
foreach my $value ( in($object->{Value}) ) {
print "$value ";
}
say "}";
} else {
say " $object->{Name} = ". ($object->{Value} // "");
}
}
say "----------------------------------";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment