How do I find the 10 largest files in a directory structure?
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.
This can be simplified a bit because Directories have no length:
gci . -r | sort Length -desc | select fullname -f 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With