Collaborate, Innovate, Automate

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:

Prerequisites

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