Managing Logical Disk Drives

Microsoft® Windows® 2000 Scripting Guide

A physical disk drive is the cornerstone of any storage management system. However, after a physical disk drive has been installed, neither users nor system administrators typically deal with the hardware directly. Instead, both users and system administrators interact with the logical drives that have been created on the disk.

A logical drive is a subdivision of a partition that has been assigned its own drive letter. (It is possible to have a partition that has not been assigned a drive letter.) When you talk about drive C or drive D, you are referring to a logical drive rather than to a physical disk drive. Likewise, when you save a document to drive E, you are saving it to the logical drive. Physical disks compose the hardware that makes up a drive, including such components as heads, sectors, and cylinders. Logical drives, by contrast, have properties such as disk space, available disk space, and drive letters.

The properties of a logical drive can be retrieved using the Win32_LogicalDisk class. A subset of properties available through this class is shown in Table 10.3.

Note

  • The Win32_LogicalDisk class can be used only to enumerate the properties of local disk drives. However, you can use the Win32_MappedLogicalDisk class to enumerate the properties of mapped network drives.

Table 10.3 Win32_LogicalDisk Properties

Property

Description

Compressed

Indicates whether the logical volume exists as a single compressed entity, such as a DoubleSpace volume. If file-based compression is supported (such as on NTFS), this property is False.

DeviceID

Unique identifier of the logical disk from other devices on the system.

DriveType

Numeric value corresponding to the type of disk drive this logical disk represents. Values are:

0 - Unknown

1 - No Root Directory

2 - Removable Disk

3 - Local Disk

4 - Network Drive

5 - Compact Disc

6 - RAM Disk

FileSystem

File system on the logical disk.

FreeSpace

Space available on the logical disk.

MaximumComponentLength

Maximum length of a file name component (the portion of a file name between backslashes) supported by the Win32 drive. The value can indicate that long names are supported by the specified file system.

MediaType

Type of media currently present in the logical drive. The value might not be exact for removable drives if there is no media currently in the drive. Values include (but are not limited to):

0 - Format is unknown

1 - 5.25-inch floppy disk (1.2Mb, 512 bytes/sector)

2 - 3.5-inch floppy disk (1.44Mb, 512 bytes/sector)

3 - 3.5-inch floppy disk (2.88Mb, 512 bytes/sector)

4 - 3.5-inch floppy disk (20.8Mb, 512 bytes/sector)

11 - Removable media other than floppy

12 - Fixed hard disk media

20 - 3.5-inch floppy disk (128Mb, 512 bytes/sector)

21 - 3.5-inch floppy disk (230Mb, 512 bytes/sector)

Name

Label by which the object is known.

Size

Size of the disk drive.

SupportsFileBasedCompression

Indicates whether the logical disk partition supports file-based compression, such as is the case with NTFS. This property is False when the Compressed property is True.

SystemName

Name of the computer where the drive is installed.

VolumeName

Volume name of the logical disk. (Maximum 32 characters.)

VolumeSerialNumber

Volume serial number of the logical disk. (Maximum 11 characters.)

Scripting Steps

Listing 10.3 contains a script that enumerates the properties of all the logical disk drives on a computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.

  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."

  3. Use the ExecQuery method to query the Win32_LogicalDisk class.

    This query returns a collection consisting of all the logical disk drives installed on the computer.

  4. For each logical disk drive in the collection, echo the drive properties, including the DeviceID, the type of file system installed on the drive, the drive type, and the amount of free space available on the drive.

Listing 10.3 Enumerating Logical Disk Drive Properties

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_LogicalDisk")
For each objDisk in colDisks
 Wscript.Echo "Compressed: " & objDisk.Compressed 
 Wscript.Echo "Description: " & objDisk.Description 
 Wscript.Echo "Device ID: " & objDisk.DeviceID 
 Wscript.Echo "Drive Type: " & objDisk.DriveType 
 Wscript.Echo "FileSystem: " & objDisk.FileSystem 
 Wscript.Echo "FreeSpace: " & objDisk.FreeSpace 
 Wscript.Echo "MediaType: " & objDisk.MediaType 
 Wscript.Echo "Name: " & objDisk.Name 
 Wscript.Echo "Size: " & objDisk.Size 
 Wscript.Echo "SupportsFileBasedCompression: " & _
 objDisk.SupportsFileBasedCompression 
 Wscript.Echo "SystemName: " & objDisk.SystemName 
 Wscript.Echo "VolumeName: " & objDisk.VolumeName 
 Wscript.Echo "VolumeSerialNumber: " & _
 objDisk.VolumeSerialNumber 
Next