The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 07-06-2007
caddyjoe77 caddyjoe77 is offline
Registered User
 

Join Date: Apr 2005
Posts: 30
thanks for the help on this; i actually used that particular foreach example from a PERL book i had gotten. Bear in mind i am NOT much of a PERL programmer but definitely trying to learn.

here is the final script that at least goes all the way through the script without erroring except RPC server not available. Strange, i think i need to add some DNS checking or something to resolve the hostname or NBT.

use Win32::OLE;
use Win32::OLE('in');
use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;
#use Win32::AdminMisc;

#Read from your selected file, make sure the path is right; you must use \\ or UNC \\\\
#$computer="gws-379txt1337";
open(DATA,"<hosts.txt \n") || die "Could not open File!, check the path! \n";

while( my $computer = <DATA>)
{
print $computer;
foreach $computer(in(<DATA>))
{
$objWMIService = Win32::OLE->GetObject
("winmgmts:\\\\$computer\\root\\CIMV2") || die "WMI connection failed.\n";
$colItems = $objWMIService->ExecQuery
("SELECT * FROM Win32_OperatingSystem","WQL",wbemFlagReturnImmediately | wbemFlagForwardOnly);

foreach my $objItem (in $colItems)
{
print "Caption: $objItem->{Caption}\n";
print "CSD Version: $objItem->{CSDVersion}\n";
print "CS Name: $objItem->{CSName}\n";
print "Name: $objItem->{Name}\n";
print "Service Pack Major Version: $objItem->{ServicePackMajorVersion}\n";
print "System Directory: $objItem->{SystemDirectory}\n";
print "Windows Directory: $objItem->{WindowsDirectory}\n";
print "\n";
}
}
}
close(DATA)

as i mentioned above, i get an RPC error and also another strange thing;

the hostnames are listed like :

the-999the-9999
the-thisis5678
th-999www9087

those are of course exampled of the format...but should i build some checking for dashes too? the computer name DOES get read into the script, i just get the RPC error on most except the example the-999the-9999.

thanks
Reply With Quote