Files

Find the Largest Files in a Folder with PowerShell

3 min read

“What’s filling this disk?” — sorted by size.

Top 20 largest files under a path

Get-ChildItem C:\ -Recurse -File -ErrorAction SilentlyContinue |
  Sort-Object Length -Descending |
  Select-Object -First 20 FullName,
    @{Name='MB'; Expression={ [math]::Round($_.Length / 1MB, 2) }}

Files larger than 1 GB

Get-ChildItem C:\Users -Recurse -File -ErrorAction SilentlyContinue |
  Where-Object Length -gt 1GB |
  Select-Object FullName, @{Name='GB'; Expression={ [math]::Round($_.Length / 1GB, 2) }}

Total size of a folder

"{0:N2} GB" -f ((Get-ChildItem C:\Logs -Recurse -File -EA SilentlyContinue |
  Measure-Object Length -Sum).Sum / 1GB)

Files not modified in over 90 days

Get-ChildItem D:\Share -Recurse -File |
  Where-Object LastWriteTime -lt (Get-Date).AddDays(-90) |
  Select-Object FullName, LastWriteTime, Length

Notes: -ErrorAction SilentlyContinue skips folders you can’t read (otherwise the scan stops on “access denied”); run elevated to see protected system folders. -File excludes directories. Suffixes KB/MB/GB/TB are built-in PowerShell number literals, so 1GB is valid as written.

Open the full version (with copy buttons) ↗

← All recipes