PowerShell: Get Free Disk Space

Need to check how much free space is left on a drive - for capacity planning, cleanup before an update, or just monitoring a server? This one-liner pulls free space for every disk on the machine, converted into a readable format.

Prerequisites:

  • Privileges: None
  • Module: Built-in, no import needed

Quick Command:

Get-CimInstance Win32_LogicalDisk | Select-Object Name, @{Name="FreeSpaceGB";Expression={[math]::Round($_.FreeSpace / 1GB, 2)}}

Example Output:

Name FreeSpaceGB
---- -----------
C:        129.61
Y:         129.6
Z:         129.6
📦
Want all of them at once?
Get every free one-liner from this blog in a single downloadable bundle organized by category, each with full comment-based help. No more copy-pasting one at a time.

How It Works:

  • Get-CimInstance Win32_LogicalDisk queries the logical disk class, which holds info about every drive letter recognized by the system, including local disks, mapped network drives, and removable media.
  • FreeSpace is returned in raw bytes by default, which isn't very readable on its own (a number like 139182841856 doesn't mean much at a glance).
  • The calculated property @{Name="FreeSpaceGB"; Expression={...}} creates a new custom column - Name sets what the column is called, and Expression is a script block that runs for each disk to compute its value.
  • Inside the expression, $_ refers to the current disk being processed, so $_.FreeSpace / 1GB converts that disk's free space from bytes into gigabytes (1GB is a built-in PowerShell unit that automatically equals 1,073,741,824 bytes).
  • [math]::Round(..., 2) rounds the result to 2 decimal places, since dividing bytes by 1GB often produces a long, unreadable decimal.