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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s