Thursday, September 23, 2010

Powershell - Find top 10 large files in a disk

Powershell make it easy to list down the files in a drive by size through a single line command. Buying a third party software can be avoided by these simple commands. The command is 

Get-ChildItem c:\ -recurse | sort -property length -desc | select -first 10  | format-table Name, Length -autosize

Get-ChildItem 

This command will list down the members of the input [ here it is C drive]. Recurse option will search all the folder under the drive mentioned

Sort -property length -desc

Sort will sort the results with the input provided by Get-Childitem command, it sorts by Size here and desc will tell the sort command to list items in descending order.

Select -first 10

This command will select the first 10 items, if you remove this command it will display all results.

Format-table Name, Length -autosize

Format-table command will format the results and display it as a table and the parameters will display only Name and Length column of the result. -autosize will tell the command to remove unwanted size and display it within the screen limits.


Windows PowerShell 2.0



No comments: