Perform a WQL Query (Perl)

This code can be found in Chapter 14 of DNS on Windows Server 2003

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# Perform a WQL query for the disks with less than 100MB free space

# ---------------------------------------------------------------
# From the book "DNS on Windows Server 2003" 
# By Cricket Liu, Matt Larson & Robbie Allen
# Publisher: O'Reilly and Associates
# ISBN: 0-596-00562-8
# Book web site: http://rallenhome.com/books/dnsonw2k3/toc.html
# ---------------------------------------------------------------

use Win32::OLE qw(in);

$strComputer = '.';
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$objDisks = $objWMI->ExecQuery('select * from Win32_LogicalDisk ' . 'where FreeSpace < 104857600 ' . 'and filesystem = \'NTFS\' ');
foreach my $objDisk (in $objDisks) {
    print 'DeviceID: ' . $objDisk->DeviceID, "\n";
    print 'Description: ' . $objDisk->Description, "\n";
    print 'FileSystem: ' . $objDisk->FileSystem, "\n";
    print 'FreeSpace: ' . $objDisk->FreeSpace, "\n";
}

This code has been viewed 944 times.

New from the creators of TechTasks.com: StatSheet.com