← script library

Find the Largest Files in a Folder with PowerShell

Windows Server RolesAugust 17, 2026

Walks a path and lists the biggest files, sorted, with sizes aligned so the list scans at a glance. The blunt instrument for a full volume: it usually turns out to be one forgotten backup, one transaction log or one core dump, and this finds all three.

powershell
# Find Largest Files
# Single use case: list the top N biggest files under a path (disk space hunts)
#-----------------------------------------------------------------

function Write-Log {
    param($Message)
    Write-Host "<WRITE-LOG = `"*$Message*`">"
}

# --- Parameters (replace via ServerEngine API parameters if needed) ---
$SearchPath = "C:\"
$TopCount   = 20

if (-not (Test-Path $SearchPath)) {
    Write-Log "Path not found: $SearchPath"
    return
}

Write-Log "Scanning $SearchPath for the $TopCount largest files (this can take a while)..."

$files = Get-ChildItem $SearchPath -Recurse -File -Force -ErrorAction SilentlyContinue |
         Sort-Object Length -Descending |
         Select-Object -First ([int]$TopCount)

if (-not $files) { Write-Log "No files found under $SearchPath."; return }

Write-Log "================ Top $TopCount Files ================"
foreach ($f in $files) {
    $gb = [math]::Round($f.Length / 1GB, 2)
    Write-Log "[$($gb.ToString().PadLeft(8)) GB] $($f.FullName)"
}

Write-Log "Largest-file scan complete."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.