How to Get Free Disk Space in PowerShell?

Many times IT admin has to requirement to know about free disk space on your local computer or free disk space percentage or free disk space on 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 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 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, 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 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 list of users logged on to server!

Using win32_logicaldisk PowerShell command

Using win32_logicaldisk PowerShell script, it 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, win32_logicaldisk command in PowerShell check disk space and get free diskspace as below

win32_logicaldisk - get disk space
win32_logicaldisk – get disk space

Cool Tip: Best way to download zip file using PowerShell!

Using Get-CimInstance PowerShell command

Using Get-CimInstance cmdlet, you can get free disk space on 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 local computer and get free disk space information for 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, Get-CimInstance command in PowerShell takes remote computer name as tom-laptop and get 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 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 ShellGeek home page.

Leave a Comment