CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
WMI + Arrays and Lists.

 



Bode
Novice

Aug 7, 2002, 5:02 AM

Post #1 of 3 (1464 views)
WMI + Arrays and Lists. Can't Post

Hello all.
I have just started usin perl. I writing a script to gather system information using WMI. However for information on a network card it returns a massive bunch of strings and I need only get 2 of these strings.

I have created an array which contains the the strings I need.

my @RETURNS = qw( 3Com 3C905C-TX);

The string which is returned by WMI needs to be assigned to an array (i think).

foreach $Object (in ($WMIServices->InstancesOf( "Win32_NetworkAdapter" ) ) ){
@cardInfo = qw($Object->{Name});
my $Returns = $cardInfo->{Name} || [];
foreach my $Ret ( @{$Returns}) {
print "\t\t$RETURNS[$Ret] || UNKNOWN \n";


So I done something like that, and try and compare, and if the string are equal then print them. If not print UNKNOWN.

Any suggestions would be really cool.

Cheers


fashimpaur
User / Moderator

Aug 7, 2002, 6:32 AM

Post #2 of 3 (1462 views)
Re: [Bode] WMI + Arrays and Lists. [In reply to] Can't Post

Bode,

I am a little unclear as to what you are trying to do. However, in your code, you
have written:


In Reply To
foreach $Object (in ($WMIServices->InstancesOf( "Win32_NetworkAdapter" ) ) ){
@cardInfo = qw($Object->{Name});
my $Returns = $cardInfo->{Name} || [];
foreach my $Ret ( @{$Returns}) {
print "\t\t$RETURNS[$Ret] || UNKNOWN \n";




It is not clear where the closing bracket '}' is for the first foreach loop.

Also, These errors are apparent from what I understand:


There is no 'in' function in Perl.
Your @cardinfo array will only catch the last network adapter name
You cannot dereference an array as a hash. @ = array $ - can be hashref


So, I think this is what you meant. If not, post back and we can discuss:


Code
  
foreach $Object (@{$WMIServices->InstancesOf( "Win32_NetworkAdapter" )}){
push @cardInfo, $Object;
}foreach my $card(@cardinfo){
print ("\t\t", ($card->{Name} || "UNKNOWN"), "\n");
}

Let me know. Hope it helps.
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


Bode
Novice

Aug 7, 2002, 8:12 AM

Post #3 of 3 (1454 views)
Re: [Bode] WMI + Arrays and Lists. [In reply to] Can't Post

Cheers for your reply.

Heres the whole script!

#!/usr/bin/perl

use vars qw ($log $message $name $value);
use Win32::OLE qw( EVENTS HRESULT in );

my @RETURNS = qw( 3Com 3C905C-TX );

#Get machine name from command line.
( my $Machine = shift @ARGV || " . " ) =~ s/^[\\\/]+//;

my $WMIServices = Win32::OLE->GetObject( "winmgmts:{impersonationLevel=impersonate,(security)}//$Machine/" ) || die "error connecting to machine $Machine. It maybe switched off.";

#Get Network Card info.
foreach $Object (in ($WMIServices->InstancesOf( "Win32_NetworkAdapter" ) ) ){
$cardName = ($Object->{Name});
print $cardName;
}



When u run it it returns loads of information - to much to enter it into a database. I have deacred in the array @RETURNS, the 2 strings which i require. So I need to compare this array with the information which is returned, which is the problem I have at the moment. And if there is a match print it.

Hope this is clear.

Cheers.

PS if u want to try this but not got a networkcard change "Win32_NetworkAdapter" for "Win32_POTSModem".
cheers

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives