Created
March 18, 2012 03:58
-
-
Save karronoli/2068736 to your computer and use it in GitHub Desktop.
get drive space size (Perl + WMI)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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