Skip to content

Instantly share code, notes, and snippets.

@karronoli
Created March 18, 2012 03:58
Show Gist options
  • Save karronoli/2068736 to your computer and use it in GitHub Desktop.
Save karronoli/2068736 to your computer and use it in GitHub Desktop.
get drive space size (Perl + WMI)
use strict;
use warnings;
use Win32::OLE;
sub getDriveSpace {
my ($drive) = @_;
my $wql = 'SELECT DeviceID, FreeSpace FROM Win32_LogicalDisk';
my $items = Win32::OLE->GetObject('winmgmts:/root/CIMV2')->ExecQuery($wql);
my %info = map {uc($_->DeviceID) => $_->FreeSpace} Win32::OLE::in $items;
return $info{uc($drive)} || 0;
}
if (!caller) {
my $drive = ($ARGV[0])? $ARGV[0]: 'c:';
print getDriveSpace($drive);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment