Script
Find large files
List files over a size threshold, largest first.
Walks a folder tree and prints files at or above the threshold. Read-only unless you pipe the output into something that deletes.
.\find-large-files.ps1 -Path .\docs -MinimumSizeMB 50
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
-Path |
string | Yes | Folder to scan. |
-MinimumSizeMB |
int | No | Size threshold in megabytes. Default 100. |
Source
<#
.SYNOPSIS
List files larger than a given size.
.PARAMETER Path
Folder to scan.
.PARAMETER MinimumSizeMB
Size threshold in megabytes. Default 100.
.EXAMPLE
.\find-large-files.ps1 -Path .\docs -MinimumSizeMB 50
#>
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$Path,
[ValidateRange(0, 1048576)]
[int]$MinimumSizeMB = 100
)
$ErrorActionPreference = 'Stop'
if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
throw "Folder not found: $Path"
}
$threshold = $MinimumSizeMB * 1MB
Get-ChildItem -LiteralPath $Path -Recurse -File -ErrorAction SilentlyContinue -ErrorVariable scanErrors |
Where-Object { $_.Length -ge $threshold } |
Sort-Object -Property Length -Descending |
Select-Object FullName, @{ Name = 'SizeMB'; Expression = { [math]::Round($_.Length / 1MB, 2) } }, LastWriteTime
if ($scanErrors.Count -gt 0) {
Write-Warning "$($scanErrors.Count) folder(s) skipped (access denied or unreadable)."
}
Downloaded it? Windows blocks scripts from the internet until you unblock them: Unblock-File -Path .\find-large-files.ps1. See Run a script.
Edit this page on GitHub Edit find-large-files.ps1 Report a problem