Powershell – How to find the 10 largest files in a directory structure

powershell

How do I find the 10 largest files in a directory structure?

Best Solution

Try this script

Get-ChildItem -re -in * |
  ?{ -not $_.PSIsContainer } |
  sort Length -descending |
  select -first 10

Breakdown:

The filter block "?{ -not $_.PSIsContainer }" is meant to filter out directories. The sort command will sort all of the remaining entries by size in descending order. The select clause will only allow the first 10 through so it will be the largest 10.