Home » PowerShell » How to Get Free Disk Space in PowerShell?

How to Get Free Disk Space in PowerShell?

Many times IT admin has the requirement to know about free disk space on your local computer or free disk space percentage or free disk space on the remote computer. In this blog post, we will see how to get free disk space using PowerShell.

There are four ways you can get free disk space with PowerShell.

Using the Get-Volume PowerShell command

Get All Volumes and space allocation

You can use Get-Volume PowerShell command to get list of all the volumes available on the system, Health Status of each drive, File System Type, total disk space allocated to drive, and most important free disk space in GB.

Get-Volume

In the above example, the PowerShell Get-Volume command on execution returns the list of all drives and their disk space information.

Get-Volume Example Output as given below

PowerShell Get-Volume (Get free disk space)
PowerShell Get-Volume (Get free disk space)

Get the volume, free disk space for a particular drive letter

Get-Volume -DriveLetter C

Above Get-Volume command returns volume object having information about C drive, File System Type, Size Allocated in GB and Free disk space in GB

Get-Volume to get free disk space for C drive Output as below

Get-Volume - Free disk space for drive in gb
Get-Volume – Free disk space for drive in gb

Cool Tip: Learn how to get current directory full path in PowerShell!

Using the Get-PSDrive PowerShell command

Get-PSDrive PowerShell command returns the list of all drive, Environment, Registry name HKCU, HKLM and total space used in GB and free available disk space in GB.

Get-PSDrive
#To get specific drive volume and size information, run below command
Get-PSDrive C

in the above example, PowerShell Get-PSDrive command returns C drive volume object details and total size remaining in GB.

PowerShell Get-PSDrive free space in GB output as below

Get-PSDrive - Free space in gb
Get-PSDrive – Free space in gb

Cool Tip: Do you know QUser command to get a list of users logged on to the server!

Using win32_logicaldisk PowerShell command

Using win32_logicaldisk PowerShell script, returns deviceId, total size allocated, and free space for each drive.

Get-WmiObject -Class win32_logicaldisk | Format-Table DeviceId, MediaType, @{n="Size";e={[math]::Round($_.Size/1GB,2)}},@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}

In the above example, the win32_logicaldisk command in PowerShell checks disk space and get free disk space as below

win32_logicaldisk - get disk space
win32_logicaldisk – get disk space

Cool Tip: The best way to download zip file using PowerShell!

Using the Get-CimInstance PowerShell command

Using Get-CimInstance cmdlet, you can get free disk space on a local computer.

Get-CimInstance -ComputerName localhost win32_logicaldisk | where caption -eq "C:" | foreach-object {write " $($_.caption) $('{0:N2}' -f ($_.Size/1gb)) GB total, $('{0:N2}' -f ($_.FreeSpace/1gb)) GB free "}

In the above example, Get-CimInstance command in PowerShell takes localhost as the local computer and gets free disk space information for the C drive as below

Get-CimInstance - Get drive size
Get-CimInstance – Get drive size

You can use below PowerShell script to get remote computer free disk space

Get-CimInstance -ComputerName tom-laptop win32_logicaldisk | where caption -eq "C:" | foreach-object {write " $($_.caption) $('{0:N2}' -f ($_.Size/1gb)) GB total, $('{0:N2}' -f ($_.FreeSpace/1gb)) GB free "}

In the above example, the Get-CimInstance command in PowerShell takes the remote computer name as tom-laptop and gets C drive total size allocated and free space in GB.

Cool Tip: Do you know how to create shortcuts on user desktop using PowerShell!

Conclusion

I hope the above article will help you to get free disk on local or remote computer using different way available in PowerShell.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment