Skip to content
Commitpedia
Log in Join & edit

Find the largest folders on a drive with PowerShell

Lists the biggest top-level folders under a path, with file counts and sizes in GB, so you can see where the disk went. Read-only: it only lists and measures.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of Find the largest folders on a drive with PowerShell: 1 recorded edit
Edit history · 1 edit
Type
Script
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Language
powershell
Licence
CC0-1.0

What this changes

Nothing. It reads folder and file sizes with Get-ChildItem and prints a table. No files are created, moved or deleted.

How to undo it

Nothing to undo. Close the window or press Ctrl+C to stop a long scan.

The disk is full and the Properties dialog shows one folder at a time. This script measures every top-level folder under a path and prints the largest ones with their sizes. Point it at a drive root, a user profile or a project folder.

The script

[CmdletBinding()]
param(
    [string]$Path = 'C:\',
    [int]$Top = 15
)

if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
    Write-Error "Folder not found: $Path"
    exit 1
}

$drive = (Get-Item -LiteralPath $Path).PSDrive
if ($null -ne $drive.Used) {
    $usedGB = [math]::Round($drive.Used / 1GB, 1)
    $freeGB = [math]::Round($drive.Free / 1GB, 1)
    Write-Host "Drive $($drive.Name): $usedGB GB used, $freeGB GB free"
}
Write-Host "Scanning $Path ..."

$results = Get-ChildItem -LiteralPath $Path -Directory -Force -ErrorAction SilentlyContinue |
    ForEach-Object {
        Write-Verbose "Measuring $($_.FullName)"
        $files = Get-ChildItem -LiteralPath $_.FullName -File -Recurse -Force -ErrorAction SilentlyContinue
        $bytes = ($files | Measure-Object -Property Length -Sum).Sum
        [pscustomobject]@{
            Folder = $_.FullName
            Files  = @($files).Count
            SizeGB = [math]::Round(($bytes / 1GB), 2)
        }
    }

$looseBytes = (Get-ChildItem -LiteralPath $Path -File -Force -ErrorAction SilentlyContinue |
    Measure-Object -Property Length -Sum).Sum
$results += [pscustomobject]@{
    Folder = "(files directly in $Path)"
    Files  = @(Get-ChildItem -LiteralPath $Path -File -Force -ErrorAction SilentlyContinue).Count
    SizeGB = [math]::Round(($looseBytes / 1GB), 2)
}

$results |
    Sort-Object SizeGB -Descending |
    Select-Object -First $Top |
    Format-Table -AutoSize

How to run it

.\Get-LargeFolders.ps1
.\Get-LargeFolders.ps1 -Path 'C:\Users\ana' -Top 10
.\Get-LargeFolders.ps1 -Path D:\ -Verbose

Save it as Get-LargeFolders.ps1. A full drive scan takes a minute or two. Run from an elevated prompt to measure folders your account cannot normally read, such as other users’ profiles; otherwise those folders show up smaller than they are because inaccessible files are skipped silently.

How it works

  • Get-ChildItem -Directory lists only folders; -File -Recurse then collects every file below each one. -Force includes hidden and system items such as $Recycle.Bin.
  • Measure-Object -Sum on Length adds the file sizes. Dividing by the 1GB constant turns bytes into gigabytes.
  • -ErrorAction SilentlyContinue keeps access-denied errors from flooding the output. Use -Verbose to see which folder is being measured.
  • A separate line counts files that sit directly in the path, so a huge file in the root does not vanish from the picture.
  • [pscustomobject] builds one row per folder, which is why the output is a real table you can sort or export.

Variations

# Drill into the biggest folder
.\Get-LargeFolders.ps1 -Path 'C:\Users\ana\AppData\Local'

# Save the table instead of printing it
.\Get-LargeFolders.ps1 -Path C:\ | Out-File folders.txt

# The 20 largest single files under a path
Get-ChildItem C:\Users\ana -File -Recurse -Force -ErrorAction SilentlyContinue |
    Sort-Object Length -Descending | Select-Object -First 20 FullName, @{N='MB';E={[math]::Round($_.Length/1MB)}}

The SizeGB figures are sums of file lengths, so they can be slightly below what Explorer reports as size on disk, and they do not include files you are not allowed to read. For a graphical view of the same data, WinDirStat and TreeSize Free are the usual tools; this script is for when you want the answer in a terminal or a log file.

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

  • 0396 PowerShell basics: cmdlets, objects and the pipeline PowerShell commands are called cmdlets, they return objects instead of text, and the pipeline passes those objects between them. Once that clicks,… Beginner · Explains an idea · Linux, macOS, Windows Article PowerShell 15 Oct 2026
  • 0397 PowerShell cheat sheet The PowerShell cmdlets and patterns you use every day: files, text, processes, services, filtering, exporting, remoting and the operators that trip up… Beginner · Cheat sheet · Linux, macOS, Windows Article PowerShell 15 Oct 2026
  • 0398 Install WSL2 and Ubuntu on Windows One command installs the Windows Subsystem for Linux and Ubuntu. Then learn how to pick a distribution, check which WSL version you… Beginner · Step by step · Windows Article Windows administration · WSL 15 Oct 2026
  • 0399 Fix: running scripts is disabled on this system (execution policy) PowerShell refuses to run .ps1 files until the execution policy allows it. The usual fix is RemoteSigned for your own user; here… Beginner · Fixes an error · Windows Article PowerShell · Windows administration 15 Oct 2026
  • 0400 winget: install and update software from the command line winget is the package manager built into Windows. Search for a program, install it by id, update everything with one command and… Beginner · Step by step · Windows Article Installing languages & tools · Windows administration 15 Oct 2026
  • 0401 Windows services, Task Scheduler and event logs from PowerShell Manage the three things Windows administrators touch most: query and restart services, create and inspect scheduled tasks, and search the event logs… Intermediate · Step by step · Windows Article PowerShell · Windows administration 15 Oct 2026

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Dominik +3,668 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?