Powershell: How to find (large) files
Using Microsoft Powershell to find large files on a specific drive recursively is very easy.
Start PowerShell as Admin (run as administrator)
To search for files larger than 100MB on Drive C type:
Get-ChildItem c:\ -Recurse | Where-Object {$_.Length -gt 100MB}
This command can also be entered abbreviated
gci c:\ -rec | where {$_.Length -gt 100mb}
to supress errors like:
Get-ChildItem : Access to the path ‘C:\Windows\System32\LogFiles\WMI\RtBackup’ is denied.
At line:1 char:4
+ gci <<<< c:\ -rec | where {$_.Length -gt 100mb}
+ CategoryInfo : PermissionDenied: (C:\Windows\Syst…es\WMI\RtBackup:String) [Get-ChildItem], Unauthoriz
edAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
use the -errorAction instruction
Get-ChildItem c:\ -Recurse -ErrorAction "SilentlyContinue" | Where-Object {$_.Length -gt 100MB}
or
gci c:\ -rec -ErrorAction "SilentlyContinue" | where {$_.Length -gt 100mb}
To export the results to a Microsoft Excel CSV or XML File
Get-ChildItem c:\ -Recurse -ErrorAction "SilentlyContinue" | Where-Object {$_.Length -gt 100MB} | Export-Csv c:\temp\myLargeFilesOnC_Report.csv
or
Get-ChildItem c:\ -Recurse -ErrorAction "SilentlyContinue" | Where-Object {$_.Length -gt 100MB} | Export-Clixml c:\temp\myLargeFilesOnC_report.xml
feel free to comment!
Nice article !
I have developed a Powershell cmdlet Find-ChildItem which provides all the required features. It is equivalent to unix/linux find command
Check out this link: http://windows-powershell-scripts.blogspot.com/2009/08/unix-linux-find-equivalent-in.html
Hi,
i use this script to get files over 400MB on a server.
i had many errors like “access denied”. it means it doesn’t find all files. but when i search with the explorer, then no warning occurs and all files are listed.
What may be the problem?
Hi Markus
Did you start the PowerShell elevated/as Admin?
cheers, Chris
Hi Chris, any way to get this to display the outup in GB? Adding / 1GB returns a syntax error.
I know nothing about powershell. Great tip to make me look like I do know something about it.