Hi Monks,
I'm looking to create a script than monitors drive usage on various w2k3 boxes.
It will be running from a w2k3 box itself and needs to gather the following info over the network:
Fixed Drives in servers
Drive capacity
Used capacity
I have performed some tests with Win32::AdminMisc and Win32::DriveInfo but have not managed to get them to work over the network.
use strict;
use Win32::DriveInfo;
use Win32::AdminMisc;
use Data::Dumper;
#################
my $target = '\\\\server\\c\\';
my @diskinfo = Win32::DriveInfo::DriveSpace($target);
print Dumper \@diskinfo;
#################
@diskinfo = Win32::AdminMisc::GetDriveGeometry($target);
print Dumper \@diskinfo;
exit 0;
All tests result in undefined arrays.
Am I even using the correct modules? Is my code correct? Any help would be grately appreciated.
Thanks,
TeraMarv.
UPDATE:
I have finally got it to work thus:
use strict;
use Win32::DriveInfo;
use Win32::NetAdmin;
use Data::Dumper;
my $capacity_href;
my @servers = ('hqteradcm1','hqteradcm2','hcodevj248');
for my $server (@servers) {
my @disks;
my $target = '\\\\'.$server.'\\';
# Find all drives on server $target
Win32::NetAdmin::GetServerDisks($target, \@disks);
# Change array elements from C: to \\\\server\\c$\\
map { s/(.*):/$target\L$1\$\\/; } @disks;
for my $drive (@disks) {
# Find drive types
my $type = Win32::DriveInfo::DriveType($drive);
# Test for valid drive types -
if($type =~ /(?:3|4)/) {
# Find total and free space on drive
my ($total,$free) = (Win32::DriveInfo::DriveSpace($driv
+e))[5,6];
$drive =~ s/^\\\\.*\\(.)\$\\/\U$1:\//;
$capacity_href->{$server}->{$drive} = { total => $total
+,
free => $free
};
}
}
}
print Dumper $capacity_href;
exit 0;
Ouput from Dumper:
---------- Capture Output ----------
> "C:\Perl\bin\wperl.exe" DriveSpace.pl
$VAR1 = {
'hqteradcm1' => {
'E:/' => {
'free' => '10177232896',
'total' => '18449301504'
},
'C:/' => {
'free' => 3358816256,
'total' => '18457527808'
}
},
'hcodevj248' => {
'E:/' => {
'free' => '5279924224',
'total' => '18449301504'
},
'C:/' => {
'free' => '11348357632',
'total' => '18457527808'
}
},
'hqteradcm2' => {
'E:/' => {
'free' => '16571375616',
'total' => '36964372480'
},
'C:/' => {
'free' => 718196224,
'total' => '8595417088'
},
'F:/' => {
'free' => '26558570496',
'total' => '28311412736'
}
}
};
> Terminated with exit code 0.