Get a Folder's Total Size with PowerShell (du for Windows)

Sum file sizes recursively with Get-ChildItem and Measure-Object Length -Sum to see how much space a folder occupies.

WindowsFilesdisk-spacepowershellLow risk
Run (Get-ChildItem 'C:\folder' -Recurse -File -Force | Measure-Object Length -Sum).Sum and divide by 1MB.

01Command

Command
$ "{0:N2} MB" -f ((Get-ChildItem 'C:\Users\me\Downloads' -Recurse -File -Force -ErrorAction SilentlyContinue |
  Measure-Object Length -Sum).Sum / 1MB)

02What it does

Windows File Explorer's folder Properties shows size, but from the command line the standard equivalent of du is piping Get-ChildItem -Recurse -File into Measure-Object Length -Sum. -Force includes hidden files, and -ErrorAction SilentlyContinue skips folders you can't read (like system-protected ones) instead of aborting. Divide by 1MB or 1GB to make the raw byte count readable; to compare many folders at once, group the results per top-level directory.

03Risk

RiskLow risk
!Warning: On huge trees (C:\Windows, whole user profile) this can take several minutes and read a lot of metadata from disk.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Measure-Object
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Measure-Object Length -Sum totals the file sizes piped from Get-ChildItem, the standard way to compute folder size in PowerShell.
  • Measure-Object - SS64
    SS64 · technical · 2026-09-17
    Evidence: Shows -Sum aggregation of numeric properties like file Length.

Last verified: 2026-09-18 · Category: Files & Folders

06Related solutions