# 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](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) 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.

Batch script to list disk drives

wmic logicaldisk get deviceid

   1

  wmic logicaldisk get deviceid

   

 

  

[![List of all available disk drives on a Windows device](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Disk-drives-available-on-a-Windows-device.png)](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Disk-drives-available-on-a-Windows-device.png)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`.

Batch script to fetch disk drive details

wmic logicaldisk get deviceid, description, size

   1

  wmic logicaldisk get deviceid, description, size

   

 

  

[![Details of disk drives on a Windows device](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Details-of-disk-drives-on-a-Windows-device.png)](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2023/01/Details-of-disk-drives-on-a-Windows-device.png)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

Script to get drives in the current session

Get-PSDrive

   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.

[![List of all available drives on Windows device](https:2023/01/Drives-available-on-Windows-device.png)](https:2023/01/Drives-available-on-Windows-device.png)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.

Script to fetch info for a specific drive

Get-PSDrive C

   1

  Get-PSDrive C

   

 

  

[![Information about a specific drive](https:2023/01/Info-about-a-specific-drive.png)](https:2023/01/Info-about-a-specific-drive.png)### 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.

Script to list items of a drive

Set-Location C:\\ Get-ChildItem 

   1

2

  Set-Location C:\\

Get-ChildItem 

   

 

  

[![List of items stored on a drive](https:2023/01/Items-stored-on-a-drive.png)](https:2023/01/Items-stored-on-a-drive.png) 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.