Find Large Files on File Share
This PowerShell script scans a specified file share or local directory path and identifies all files larger than 20MB. It is useful for storage audits, capacity planning, and preparing for migrations where large files may need special handling.
Purpose
This script helps with file system analysis by:
- Recursively scanning a directory path for large files
- Reporting a count of files exceeding 20MB
- Optionally listing the large files for review
- Identifying storage-heavy content before migration or cleanup
Prerequisites
- PowerShell 5.1 or later
- Read access to the file share or directory being scanned
- A valid local or UNC path (e.g.
C:\Dataor\\server\share)
PowerShell Script
$path = Read-Host -Prompt 'Please enter the file path you wish to scan for large files...'
$rawFileData = Get-ChildItem -Path $path -Recurse
$largeFiles = $rawFileData | Where-Object { $_.Length -gt 20MB }
$largeFilesCount = $largeFiles | Measure-Object | Select-Object -ExpandProperty Count
Write-Host "You have $largeFilesCount large file(s) in $path"
$results = Read-Host -Prompt 'Do you want to display the files? Enter Y or N'
if ($results -eq 'Y') {
Write-Host $largeFiles
}
elseif ($results -eq 'N') {
Write-Host 'Query ended'
}
else {
Write-Host 'Invalid input. Query ended.'
}
PowerShell Script — Export to CSV
This version filters directories out of the results using the -File flag, and exports the large files to a CSV on the desktop instead of printing to the console. Each row includes the file name, directory, and size in MB.
$path = Read-Host -Prompt 'Please enter the file path you wish to scan for large files...'
$rawFileData = Get-ChildItem -Path $path -Recurse -File
$largeFiles = $rawFileData | Where-Object { $_.Length -gt 20MB }
$largeFilesCount = $largeFiles | Measure-Object | Select-Object -ExpandProperty Count
Write-Host "You have $largeFilesCount large file(s) in $path"
$results = Read-Host -Prompt 'Do you want to display the files? Enter Y or N'
if ($results -eq 'Y') {
$largeFiles | Select-Object Name, Directory, @{Name="Size (MB)"; Expression={[math]::Round($_.Length / 1MB, 2)}} | Export-Csv -Path "$env:USERPROFILE\OneDrive\Desktop\LargeFiles.csv" -NoTypeInformation
Write-Host "The list of large files has been saved as LargeFiles.csv on the desktop."
}
elseif ($results -eq 'N') {
Write-Host 'Query ended'
}
else {
Write-Host 'Invalid input. Query ended.'
}
Usage Notes
- Enter a full local path (e.g.
C:\Users\Documents) or a UNC network path (e.g.\\server\share) - The scan is recursive — all subdirectories are included
- The 20MB threshold can be adjusted by changing
20MBin the script to any value (e.g.50MB,100MB) - On large file shares the scan may take several minutes to complete
- Ensure you have sufficient read permissions on the target path before running
- The CSV export version saves to
OneDrive\Desktop\LargeFiles.csv— update the path if your Desktop is not synced to OneDrive