Powershell

How to Use PowerShell to Get Free Disk Space

Majority of the time, it is required to get the free disk space in Windows to perform some specific operation. The free disk space can be found using GUI(Graphical User Interface). However, PowerShell can also be used for this purpose. More specifically, PowerShell has several cmdlets including “Get-Volume” and “Get-PSDrive” to get free disk space.

This post will cover the details to get free disk space in PowerShell.

How to Use PowerShell to Get Free Disk Space?

These are the approaches to retrieve the free disk space of the drive:

Method 1: Use the “Get-Volume” Cmdlet to Get the Free Disk Space

The cmdlet “Get-Volume” is utilized to retrieve the volume of the specified disk including total and free size. If the parameters are not provided, then it will get the disk size of all the drives.

Example 1: Get the Free Disk Space of All the Available Disks

This example will execute the “Get-Volume” cmdlet to retrieve the free disk space of all the drives on the system:

Get-Volume

 

Example 2: Get the Free Disk Space of a Specific Disk

In this illustration, the free disk space of a “C” drive will be retrieved:

Get-Volume -DriveLetter C

 
According to the above code snippet:

    • First, specify the “Get-Volume” cmdlet.
    • After that, add the “-DriveLetter” parameter and assign the required drive letter:

 

As you can see, the remaining size of the “C” drive is “3.02” GBs.

Method 2: Use the “Get-PSDrive” Cmdlet to Get the Free Disk Space

The cmdlet “Get-PSDrive” gets the specified drive details in the current session. If in case the parameters are not provided to this cmdlet, then it will get all the drives in the current session.

Example 1: Get the Free Disk Space of Current Session Drives

In this code example, the free disk space of all the available disks of the current session will be retrieved:

Get-PSDrive

 

Example 2: Get the Free Disk Space of a Specific Disk Using the “Get-PSDrive” Cmdlet

This demonstration will get the free disk space of a disk specified by the user:

Get-PSDrive C

 
In the above code line, first, specify the “Get-PSDrive” and then define the drive letter “C” to it:


That was all about getting the free disk space in PowerShell.

Conclusion

The free disk in PowerShell can be retrieved using several methods. For instance, using the “Get-Volume”, and “Get-PSDrive” cmdlets. Both methods can get free disk spaces for all the available drives when used without parameters. Moreover, to get the free disk space of a single disk, respective parameters are used. In this write-up, methods to get the free disk space in PowerShell have been explained.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.