Need to check disk space usage in PowerShell? Start with the simple command `Get-WmiObject Win32_LogicalDisk | Select-Object Name, Size, FreeSpace, DriveType | Format-Table -AutoSize`, which instantly lists all drives with their total and free space. For a more detailed breakdown by file type, `Get-ChildItem -Path C:\ -Recurse -File | Measure-Object` quantifies file sizes on your C: drive—both methods work instantly on any Windows PC.
What You'll Need
- Administrator privileges for advanced checks (like scanning all drives)
- An active connection to the Windows command line (PowerShell)
- Optional: A text editor (like Notepad) to review results if you want to save them
Step-by-Step
- Open PowerShell as Administrator Press Win + X, then select Windows Terminal (Admin) or PowerShell (Admin). If prompted by UAC, click Yes. This ensures your script has full permissions to check all drives.
-
Run the basic disk summary command
Type this command and press Enter>:
Get-WmiObject Win32_LogicalDisk | Select-Object Name, Size, FreeSpace, DriveType | Format-Table -AutoSizeThis shows a clean table of all connected drives (including virtual ones), their total capacity, free space, and whether they’re local or network drives. FreeSpace is in bytes—you can convert to GB by dividing by 1GB (1,024,1024,1024).
-
Check file sizes for a specific folder (e.g., C:)
To see how much space files are using on your system drive, run:
Get-ChildItem -Path C:\ -Recurse -File | Measure-ObjectThis will output a summary like Count: 500000 (files) and Bytes: 35GB. Adjust the path (e.g., `D:\Documents`) to scan another location. Use -Recurse for nested folders.
-
Save results to a file
To export the output (useful for tracking storage over time), use:
Get-WmiObject Win32_LogicalDisk | Select-Object Name, Size, FreeSpace | Out-File -Encoding UTF8 "C:\disk_usage_$(Get-Date -Format 'yyyyMMdd').txt"This saves a timestamped file to your C: drive. Open it in Notepad or any text editor.
-
Filter for large files
To find files consuming >500MB on your desktop, run:
Get-ChildItem -Path C:\Users\YourUsername\Desktop -File | Where-Object { $_.Length -gt 500MB } | Select-Object Name, LengthReplace `YourUsername` with your actual Windows username. The result shows files over 500MB in bytes.
Common Mistakes
- Running as non-admin Without admin rights, PowerShell may report only local drives (not network or virtual ones). Always use the admin prompt.
- Ignoring drive types The `DriveType` column helps distinguish between local (3) and network/CD drives (5 or 6). Misidentify a network drive as local and you’ll miss its usage.
- Not converting units PowerShell outputs sizes in bytes. Convert to GB by dividing by 1GB (1,073,741,824) or use the `-f` flag:
- Overlooking virtual drives Tools like Docker or Hyper-V create virtual drives. Use the command to see them too; they’re indicated with `DriveType` value 2.
Tips
-
Use wildcards for large folders
To check space for all folders named "Downloads" (regardless of drive), use:
Get-ChildItem -Path *\Downloads* -Recurse -File | Measure-Object -
Compare drives side-by-side
Combine two drives into one table with:
Get-WmiObject Win32_LogicalDisk -Filter "DriveType=3" | Select-Object Name, Size, FreeSpace | Format-Table -AutoSize -WrapThen add a second drive’s results to the same session. - Schedule regular checks Save the script to a .ps1 file and use Task Scheduler (Windows) to run it weekly. Example task name: "DiskUsageCheck."
-
Avoid `Get-WmiObject` for modern Windows
This method works on older systems but may fail on Windows 10/11 with newer WMI providers. Try replacing it with:
Get-PSDrive -PSProvider FileSystem | Select-Object Name, UsedBytes, FreeBytes -
Check for hidden/system files
To include hidden/system files (e.g., Windows updates), run:
Get-ChildItem -Path C:\ -Recurse -Force -File | Measure-Object(The `-Force` flag bypasses hidden file checks.)
Troubleshooting
-
Command not recognized
If PowerShell says "The term 'Get-WmiObject' is not recognized," you’re likely on a newer Windows version. Replace it with:
Get-PSDrive -PSProvider FileSystem | Select-Object Name, UsedBytes, FreeBytesThis uses the more reliable FileSystem provider. -
No drives listed
If nothing appears, check:
- Are you running as admin?
- Is your system drive (C:) mounted correctly?
- Try adding `-ErrorAction SilentlyContinue` to the command to suppress errors and see what fails.
-
Slow performance on large drives
For drives with millions of files, use:
Get-ChildItem -Path C:\ -Recurse -File | Measure-Object -ErrorAction SilentlyContinueAdd `-ErrorAction Stop` to halt execution at the first error. - Results show ~0 bytes free Verify the drive isn’t a network drive (use `DriveType` column) or a virtual one. For network drives, add `-Credential` to specify a username/password if needed.
Frequently Asked Questions
How do I check disk usage for a specific folder (e.g., Downloads) in PowerShell?
Use this command to target the Downloads folder: . Replace `YourUsername` with your account name.
Why does PowerShell show 0 free space on a drive that has files?
This often happens if the drive is a virtual one (like Docker) or a network drive. Check the `DriveType` column in your results. Virtual drives may appear as local but aren’t physically assigned space.
Can I use this command on a Linux system?
No. This guide is for Windows only. On Linux, use commands like du -sh /path/to/folder or tools like `ncdu` for interactive disk usage analysis.
How do I find the largest files in my C: drive?
Sort the file list by size and pick the top entries: Get-ChildItem -Path C:\ -Recurse -File | Sort-Object -Property Length -Descending | Select-Object Name, Length | Take-Number 10. Use `Take-Number 10` to show only the top 10 largest files.
What if my PowerShell isn’t running from an admin prompt?
Right-click the PowerShell icon, select Run as administrator in the context menu. If you’re unsure, your results may exclude network or virtual drives.
How can I see disk usage by file extension?
Filter by extension first, then measure: Get-ChildItem -Path C:\Users\YourUsername\Downloads -Recurse -Filter *.pdf | Measure-Object -Property Length. Adjust the extension (e.g., *.mp4) to target specific file types.