How to Get Free Disk Space in PowerShell (With Example)


You can use the following syntax in PowerShell to get the free disk space on a specific drive:

Method 1: Get Free Disk Space in GB

Get-PSDrive C

This particular example will display both the free and used disk space in GB on the C drive.

Method 2: Get Free Disk Space as Percentage

Get-PSDrive C |
Select-Object @{Name="% Free Disk Space";
                Expression={$_.Free/1GB / ($_.Used/1GB + $_.Free/1GB)}}

This particular example will display the percentage of free disk space on the C drive.

The following examples show how to use each method in practice.

Example 1: Get Free Disk Space in GB Using PowerShell

We can use the following syntax to get the total free disk space in GB of the C drive on our computer:

Get-PSDrive C

The following screenshot shows how to use this syntax in practice:

PowerShell get free and used disk space

The output displays the following:

  • Used disk space: 201.73 GB
  • Free disk space: 273.99 GB

Note that we could use the following syntax if we would only like to retrieve the free disk space in GB:

(Get-PSDrive C).Free/1GB

The following screenshot shows how to use this syntax in practice:

PowerShell get free disk space in GB

Notice that the output displays only the free disk space in GB.

Example 2: Get Free Disk Space as Percentage Using PowerShell

We can use the following syntax to get the total free disk space of the C drive as a percentage:

Get-PSDrive C |
Select-Object @{Name="% Free Disk Space";
                Expression={$_.Free/1GB / ($_.Used/1GB + $_.Free/1GB)}}

The following screenshot shows how to use this syntax in practice:

PowerShell get free disk space as percentage

From the output we can see that 57.59% of the drive is free disk space.

Note that we calculated this percentage by using the following formula:

  • Free Disk Space % = Free Space / (Used Space + Free Space)
  • Free Disk Space % = 273.99 GB / (201.73 GB + 273.99 GB)
  • Free Disk Space % = 0.5759

Note: You can find the complete documentation for Get-PSDrive in PowerShell here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Get Folder Size in GB
PowerShell: How to Get Folder Size and File Count
PowerShell: How to List Files in Directory by Date
PowerShell: How to List All Files in Directory to Text File

Leave a Reply