PowerTip: Finding 10 Largest Files

Can be usefull for PowerSlim tests. For instance, in the !|Query: PowerShell|…|

Re-Posted. You can find the original here.

You may need to find the largest files for possible clean-up when free space on a drive runs low. One way is to have PowerShell examine all file sizes, sort by file size descending, and then pick the 10 largest ones (the 10 first results):

Dir $home -recurse -ea SilentlyContinue | Sort-Object Length -Descending | Select-Object -first 10 | Select-Object FullName, Length, LastWriteTime

You should note that this may take some time to complete. Also, you will see  the ErrorAction setting, which hides error messages that may occur when the command hits sub-folders or files you have no access.

Advertisements