Export (0) Print
Expand All
4 out of 5 rated this helpful - Rate this topic

Enumerating Disk Drive Properties

Microsoft® Windows® 2000 Scripting Guide

The Drives collection is typically used for inventory or monitoring purposes; as a system administrator, you need to know what drives are available on a computer, as well as details such as the drive serial number and the amount of free space on the drive. After you have returned a drives collection or an individual drive object, you can retrieve any of the properties shown in Table 4.2.

Table 4.2 Disk Drive Properties Available by Using the FileSystemObject

Property

Description

AvailableSpace

Reports the amount of free space on the drive, in bytes. To report the amount of available space in kilobytes, divide this value by 1,024. To report the amount of available space in megabytes, divide this value by 1,048,576 (1,024 * 1,024).

The AvailableSpace property reports the amount of space available to the user running the script. If disk quotas are in use on the drive, this value might be less than the total amount of free space available on the drive.

DriveLetter

Drive letter assigned to the drive. The drive letter does not include the trailing colon; thus, a floppy disk drive will be reported as A rather than A:.

DriveType

Integer value indicating the type of drive. Values include:

1 - Removable drive

2 - Fixed drive (hard disk)

3 - Mapped network drive

4 - CD-ROM drive

5 - RAM disk

FreeSpace

Reports the amount of free space on the drive, in bytes. To report the amount of free space in kilobytes, divide this value by 1,024. To report the amount of free space in megabytes, divide this value by 1,048,576 (1,024 * 1,024).

Unlike the AvailableSpace property, FreeSpace reports the total amount of free space available on the drive, regardless of whether disk quotas have been enabled.

FileSystem

Type of file system used on the drive (FAT, FAT 32, NTFS).

IsReady

Indicates whether a drive is accessible. This value will be False for floppy disk drives or CD-ROM drives where no medium is inserted.

Path

Path to the drive. For local drives, this will be the drive letter and the trailing colon (for example, A:). For mapped network drives, this will be the Universal Naming Convention (UNC) path for the drive (for example, \\Server1\SharedFolder).

RootFolder

Path to the root folder on the drive.

SerialNumber

Serial number assigned to the drive by the manufacturer. For floppy disk drives or mapped network drives, this value will typically be 0.

ShareName

Share name assigned to a mapped network drive.

TotalSize

Reports the total size of the drive, in bytes. To report the total size in kilobytes, divide this value by 1,024. To report the total size in megabytes, divide this value by 1,048,576 (1,024 * 1,024).

VolumeName

Volume name (if any) assigned to the drive.

To enumerate the drives installed on a computer, create an instance of the FileSystemObject, create a reference to the Drives property, and then use a For Each loop to iterate through the set of drives. For each drive in the collection, you can echo any or all of the individual drive object properties shown in Table 4.2.

The script in Listing 4.3 echoes all the drive properties for every drive installed on a computer.

Listing 4.3 Enumerating Disk Drive Properties

  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
 Wscript.Echo "Available space: " & objDrive.AvailableSpace
 Wscript.Echo "Drive letter: " & objDrive.DriveLetter
 Wscript.Echo "Drive type: " & objDrive.DriveType
 Wscript.Echo "File system: " & objDrive.FileSystem
 Wscript.Echo "Is ready: " & objDrive.IsReady
 Wscript.Echo "Path: " & objDrive.Path
 Wscript.Echo "Root folder: " & objDrive.RootFolder
 Wscript.Echo "Serial number: " & objDrive.SerialNumber
 Wscript.Echo "Share name: " & objDrive.ShareName
 Wscript.Echo "Total size: " & objDrive.TotalSize
 Wscript.Echo "Volume name: " & objDrive.VolumeName
Next

When the script in Listing 4.3 runs under CScript, information similar to the following appears in the command window:



Available space: 10234975744
Drive letter: C
Drive type: 2
File system: NTFS
Free space: 10234975744
Is ready: True
Path: C:
Root folder: C:\
Serial number: 1343555846
Share name:
Total size: 20398661632
Volume name: Hard Drive

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.