DEV Community

Cover image for Powershell - Get Hard Drive Size and Free Space
Dan Wheeler
Dan Wheeler

Posted on

Powershell - Get Hard Drive Size and Free Space

Run the following in a Powershell window

$disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" | Select-Object Size, FreeSpace

Write-Host ("{0}GB total" -f [math]::truncate($disk.Size / 1GB))

Write-Host ("{0}GB free" -f [math]::truncate($disk.FreeSpace / 1GB))
Enter fullscreen mode Exit fullscreen mode

To get a different drive letter, just change the C: in "DeviceID='C:'" to whatever drive you want.

Top comments (1)

Collapse
 
redhcp profile image
redhcp

Great Dan!, I posted another method here

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more