S
SimonH
Hi!
Im trying to change the following Ive worked on into using a list of
machines in a file called machine.txt
At the moment, Ive used an array of computer names im testing on. This
works, but Id like some direction on how to reference a file instead of
using an array. Any help greatly appreciated. Thank you.
I believe I might have to use a foreach statement and possibly a split
function on the machine.txt file, but not sure where to start with this.
The format of the machine.txt file is:
dell101
dell102
dell103
etc
#use diagnostics;
#use strict;
use Win32::OLE('in');
# Use the Win32_Process
my @requests = ('Win32_Process', );
# Computer list
my @computers = qw/dell101 dell102 dell103/; # having trouble
here....instead of listing, id like to reference a file called machine.txt
# Connect to each systems CimV2 repository in turn.
for my $computer( @computers ){
my $wmi_repos =
Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\$computer\\root\\CIMV2")
or die "WMI connection failed: ".Win32::OLE->LastError()."\n";
for my $request( @requests ){
my $wmi_collection = $wmi_repos->ExecQuery("SELECT * FROM $request", "WQL",
48 )
or die "WQL query failed: ".Win32::OLE->LastError()."\n";
for my $item (in $wmi_collection){
my @methods = join (", ", map {$_->{Name}}( in $item->{Methods_} ) );
my %properties = map { $_->{Name} => $_->{Value} }( in
$item->{Properties_} );
# Print results
print "\n$computer :: $request :: $properties{Name}\n", "\tMethods:
@methods\n\tProperties:\n";
for my $property( sort keys %properties ){
( $properties{$property} )
? print "\t\t$property = $properties{$property}\n"
: print "\t\t$property =\n";
} } } }
##################################################
Im trying to change the following Ive worked on into using a list of
machines in a file called machine.txt
At the moment, Ive used an array of computer names im testing on. This
works, but Id like some direction on how to reference a file instead of
using an array. Any help greatly appreciated. Thank you.
I believe I might have to use a foreach statement and possibly a split
function on the machine.txt file, but not sure where to start with this.
The format of the machine.txt file is:
dell101
dell102
dell103
etc
#use diagnostics;
#use strict;
use Win32::OLE('in');
# Use the Win32_Process
my @requests = ('Win32_Process', );
# Computer list
my @computers = qw/dell101 dell102 dell103/; # having trouble
here....instead of listing, id like to reference a file called machine.txt
# Connect to each systems CimV2 repository in turn.
for my $computer( @computers ){
my $wmi_repos =
Win32::OLE->GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\$computer\\root\\CIMV2")
or die "WMI connection failed: ".Win32::OLE->LastError()."\n";
for my $request( @requests ){
my $wmi_collection = $wmi_repos->ExecQuery("SELECT * FROM $request", "WQL",
48 )
or die "WQL query failed: ".Win32::OLE->LastError()."\n";
for my $item (in $wmi_collection){
my @methods = join (", ", map {$_->{Name}}( in $item->{Methods_} ) );
my %properties = map { $_->{Name} => $_->{Value} }( in
$item->{Properties_} );
# Print results
print "\n$computer :: $request :: $properties{Name}\n", "\tMethods:
@methods\n\tProperties:\n";
for my $property( sort keys %properties ){
( $properties{$property} )
? print "\t\t$property = $properties{$property}\n"
: print "\t\t$property =\n";
} } } }
##################################################