How to List Drives in PowerShell?

As a PowerShell developer, I have encountered requirements for getting driver details while working on my past projects. If you manage multiple servers, you can use PowerShell to manage drivers. In this tutorial, I will explain how to list drivers in PowerShell using different methods.

List All Drives Using Get-PSDrive Cmdlet

The primary cmdlet for listing drives in PowerShell is Get-PSDrive. This cmdlet displays information about all the drives available in your session, including file system drives, registry drives, and certificate stores.

To list all drives, open PowerShell and enter the following command:

Get-PSDrive

This command will output a list of all available drives, along with their properties such as name, provider, root, current location, and used/free space.

Example Output

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
C                 120.00         80.00 FileSystem    C:\
D                 200.00         50.00 FileSystem    D:\
E                 500.00        100.00 FileSystem    E:\

In this example, the drives C, D, and E are listed along with their used and free space.

I executed the above cmdlet in my local system, and you can see the output in the screenshot below:

List Drives in PowerShell

Check out Get a List of Installed Programs Using PowerShell

Filter File System Drives

Sometimes, you may only want to list file system drives and exclude other types of drives like registry or certificate stores. To achieve this, use the -PSProvider parameter with the FileSystem value:

Get-PSDrive -PSProvider FileSystem

This command will filter the output to only show file system drives.

Example Output

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
C                 120.00         80.00 FileSystem    C:\
D                 200.00         50.00 FileSystem    D:\
E                 500.00        100.00 FileSystem    E:\

Here is the output in the screenshot below:

List All Drives Using Get-PSDrive Cmdlet

Read List USB Devices Using PowerShell

Display Drive Details Using Get-Volume

To get more detailed information about each drive, you can use the Get-Volume cmdlet in PowerShell, which provides additional details such as the drive’s label, file system type, and health status.

Get-Volume

This command will display detailed information about all volumes on your system.

Example Output

DriveLetter FileSystemLabel FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- --------------- -------------- --------- ------------ ----------------- ------------- ----
C           OS              NTFS           Fixed     Healthy      OK                80.00 GB      200.00 GB
D           Data            NTFS           Fixed     Healthy      OK                50.00 GB      250.00 GB
E           Backup          NTFS           Fixed     Healthy      OK                100.00 GB     600.00 GB

Read List Local Administrators Using PowerShell

List Drives on Remote Computers using PowerShell Using Invoke-Command

PowerShell allows you to list drives on remote computers using the Invoke-Command cmdlet. This is particularly useful for network administrators managing multiple systems.

To list drives on a remote computer named Server01, use the following command:

Invoke-Command -ComputerName Server01 -ScriptBlock { Get-PSDrive -PSProvider FileSystem }

Example Output

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
C                 150.00         50.00 FileSystem    C:\
D                 100.00         75.00 FileSystem    D:\

Automate Drive Checks with PowerShell Scripts

Automating routine drive checks can save time and ensure consistent monitoring. Below is an example script that lists all file system drives and their free space, then saves the output to a text file.

Example Script

# Define the output file path
$outputFile = "C:\DriveReport.txt"

# Get all file system drives
$drives = Get-PSDrive -PSProvider FileSystem

# Create or overwrite the output file
New-Item -Path $outputFile -ItemType File -Force

# Loop through each drive and append its details to the output file
foreach ($drive in $drives) {
    $driveInfo = "Drive: $($drive.Name) - Used: $([math]::round($drive.Used / 1GB, 2)) GB - Free: $([math]::round($drive.Free / 1GB, 2)) GB"
    Add-Content -Path $outputFile -Value $driveInfo
}

# Output the path to the report file
Write-Output "Drive report saved to $outputFile"

Running the Script

Save the script to a .ps1 file and run it in PowerShell:

.\DriveReport.ps1

This script will generate a report of all file system drives and their free space, saving it to C:\DriveReport.txt.

Conclusion

In this tutorial, I explained how to list drives in PowerShell using various cmdlets such as Get-PSDrive and Get-Volume, etc. I have also explained how to list drives on remote computers using PowerShell.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.