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!
Loading...
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