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.
Batch script
List hard drives
This will list all hard disk drives available on the device.
1 |
wmic logicaldisk get deviceid |
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
.
1 |
wmic logicaldisk get deviceid, description, size |
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
1 |
Get-PSDrive |
This will list all the available PowerShell drives, i.e., all the drives that can be accessed via PowerShell on the 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.
1 |
Get-PSDrive C |
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.
1 2 |
Set-Location C:\ Get-ChildItem |