Enumerate all logical disks (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.

# Enumerate all the logical disks

# ---------------------------------------------------------------
# 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 'in';
my $strComputer = ".";
my $objWMI = Win32::OLE->GetObject("winmgmts:\\\\$strComputer\\root\\cimv2");
my $objDisks = $objWMI->InstancesOf("Win32_LogicalDisk");
for my $objDisk (in $objDisks) {
    print "DeviceID: ", $objDisk->DeviceID,"\n";
    print "FileSystem: ", $objDisk->FileSystem  ,"\n";
    print "FreeSpace: ", $objDisk->FreeSpace,"\n";
    print "Name: ", $objDisk->Name,"\n";        
    print "Size: ", $objDisk->Size,"\n";
    print "\n";
}

This code has been viewed 859 times.

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