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.



In reply to Finding Drive usage info with Win32 by TeraMarv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.