Category filter

Script to list the drives on Windows devices

A drive facilitates the storage and retrieval of data on a device. It can be a physical drive in the form of a hard disk drive, or it can be a cloud drive, stored on a remote server. Enabling the administrators to access details about the drive, including the size, list of the contents stored on it, etc., helps them draw insights about the device’s file system. You can do so by deploying customized script using Hexnode’s Execute Custom Script action.

Disclaimer:

The sample scripts provided below are adapted from third-party open-source sites.

Batch script

List hard drives

This will list all hard disk drives available on the device.

List of all available disk drives on a Windows device

You can also fetch details such as the description and the size (in bytes) of the disk drives by adding parameters such as description and size.

Details of disk drives on a Windows device

The details that are fetched are displayed in a tabular manner.

Description : It lists the type of drive.

DeviceID : It lists the identifier of the drive.

Size : It lists the total size of the drive in bytes.

PowerShell script

List all drives

This will list all the available PowerShell drives, i.e., all the drives that can be accessed via PowerShell on the device.

List of all available drives on Windows device

The details that are fetched are displayed in a tabular manner.

Name : It lists the name of the drive.

Used (GB) : It lists the memory usage (in GB) by the drive.

Free (GB) : It lists the available memory space (in GB) in the drive.

Provider : It lists the provider of the drive, which defines the logic that is used to access, navigate, and edit the drive to the computer.

Root : It lists the root directory of the drive.

CurrentLocation : It lists the path location at which the drive is stored on the device.

Fetch drive info

You can also fetch details of a specific PowerShell drive by mentioning the drive name. For example, if you have to fetch information about the C drive, you can use the following script.

Information about a specific drive

List items on a drive

Once you know all the available drives on your device, you can deploy the following script to list all the items present in a drive. The script lists all items present in the C drive.

List of items stored on a drive
Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository