Softomotive Software Solutions

The power of Windows Scripting without the hassle!

Get Disk Drive Capacity

Download the ScriptAhead File: GetDiskDriveCapacity.saf

The Problem:
You want a script that displays the list of hard disk drives installed in a computer on your network along with the capacity of each drive.

The Solution:
Step 1: The script must prompt the user for the name of the computer whose drives must be retrieved. To do so you will use the "Display Input Dialog" task.

In the dialog box you enter the message to be displayed in the input dialog as well as the name of the variable where the user answer will be stored (in this case the default variable name $InputDialogAnswer has been replaced by $ComputerName to make the script more easy to read)

 

Step 2: To retrieve all hard disk drives from the computer specified by the user you will use the "Get Disk Drive" task

In the dialog box you must choose to get Disk Drives from remote computers. In the "Computer(s)" field you enter the $ComputerName variable, which holds the computer name entered by the user.

Step 3: Now you have a collection of Win32_DiskDrive objects stored in $DiskDrives. You want to display the name and the size of each drive. To do so you will use the "Display Message" task twice.

The first "Display Message" task will be used to display the header info:

The second "Display Message" task will be used to display the actual info. Since you are only interested in the name and the size of the drive you will use the appropriate properties of the Win32_DiskDrive object (i.e. $DiskDrives.Name and $DiskDrives.Size). Because the size is represented in bytes you will divide it by 1000000000 to convert it to GB.

Note that since the $DiskDrives variable contains a collection of objects, instead of a single object, this task is smart enough to implicitly create a loop in order to display the requested properties for all the objects of the collection. This means that if a computer has more than one hard disk drives installed one line of data will be displayed for each drive.

 

Finally the completed script is:

 

You may either run the script from within ScriptAhead or just generate it in a wsf file and use it independently.