Created
October 4, 2011 05:40
-
-
Save aero/1260973 to your computer and use it in GitHub Desktop.
Query remote serverinfo via Windows WMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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