PowerShell: Get Total Disk Size

Need to check the total capacity of a drive - for inventory, capacity planning, or comparing against free space? This one-liner pulls the total size 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="Size";Expression={[math]::Round($_.Size / 1GB, 2)}}

Example Output:

Name   Size
----   ----
C:   254.51
Y:   228.27
Z:   228.27
📦
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.
  • Size returns the total capacity of the drive in raw bytes by default, which isn't very readable on its own.
  • The calculated property @{Name="Size"; Expression={...}} creates a custom column that converts the raw byte value into gigabytes - $_.Size / 1GB divides the current disk's size by 1GB (a built-in PowerShell unit equal to 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.

Pro Tip:

Combine this with free space to see both total and remaining capacity in one view:

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