neo1491 has asked for the wisdom of the Perl Monks concerning the following question:

Hello again Monks, I'm attempting to identify multiple disk drives attached to a Windows 2K3 Server. The following script gives me all the info I require EXCEPT THE DRIVE LETTER (ie: Drive C:). Any help would be much appreciated.
#!C:/Perl/bin/perl.exe -w use strict; use warnings; use Win32::OLE qw(in); my $server = Win32::NodeName(); my $user = ""; my $pwd = ""; my $locatorObj = Win32::OLE->new('WbemScripting.SWbemLocator') || die "Error creating locator object: ".Win32::OLE->LastError()."\n"; $locatorObj->{Security_}->{impersonationlevel} = 3; my $serverObj = $locatorObj->ConnectServer($server,'root\cimv2',$user, +$pwd) || die "Error connecting to $server: ".Win32::OLE->LastError()."\n"; my %disk = (); foreach my $drive (in $serverObj->InstancesOf("Win32_DiskDrive")) { $disk{$drive->{Index}}{DeviceID} = $drive->{DeviceID}; $disk{$drive->{Index}}{Manufacturer} = $drive->{Manufacturer}; $disk{$drive->{Index}}{Model} = $drive->{Model}; $disk{$drive->{Index}}{InterfaceType} = $drive->{InterfaceType}; $disk{$drive->{Index}}{MediaType} = $drive->{MediaType}; $disk{$drive->{Index}}{Partitions} = $drive->{Partitions}; $disk{$drive->{Index}}{Signature} = $drive->{Signature}; $disk{$drive->{Index}}{Size} = $drive->{Size}; } foreach my $dd (sort keys %disk) { if ($disk{$dd}{DeviceID}) { print "DeviceID : ".$disk{$dd}{DeviceID}."\n"; } if ($disk{$dd}{Manufacturer}) { print "Manufacturer : ".$disk{$dd}{Manufacturer}."\n"; } if ($disk{$dd}{Model}) { print "Model : ".$disk{$dd}{Model}."\n"; } if ($disk{$dd}{InterfaceType}) { print "InterfaceType : ".$disk{$dd}{InterfaceType}."\n"; } if ($disk{$dd}{MediaType}) { print "MediaType : ".$disk{$dd}{MediaType}."\n"; } if ($disk{$dd}{Partitions}) { print "Partitions : ".$disk{$dd}{Partitions}."\n"; } if ($disk{$dd}{Signature}) { print "Signature : ".$disk{$dd}{Signature}."\n"; } if ($disk{$dd}{Size}) { print "Size : ".$disk{$dd}{Size}." Bytes.\n"; } print "\n"; }

Replies are listed 'Best First'.
Re: Finding the Disk Drive Letter
by dHarry (Abbot) on Nov 12, 2008 at 15:17 UTC

    Have you tried Win32::DriveInfo already?

    UPDATE
    Maybe I was optimistic, ran some tests and can't get it to work on Windows XP. Make sure you read the Caveats section in the doc.

      Yep, that'll work. Can't believe I didn't find that... THANKS!