As many of you may have noticed from one of my previous post, (Monitor CPU and Memory Usage with Just One Click in Windows 7), I am doing a little research about Powershell. The new script language that is shipped with Windows 7.
Today I want to show you how to find the top 10 of largest files in a computer using this new feature.
Presenting the Script
The idea behind the script is quite simple: sort files by size and show the 10 largest. I have chosen to show even the hidden ones.
@echo off
Powershell -noexit "Get-PSdrive | where { $_.Used -gt 0 } | foreach { Get-ChildItem $_.Root -recurse -force -ErrorAction SilentlyContinue | Select Name,DirectoryName, @{Label='Size';Expression={($_.Length/1GB).ToString('F04')}} | Sort Size -descending | select -first 10}"
As you see the script is quite simple, it will show the 10 biggest files of every drive connected to your computer.
Ed Note: This script will run for each drive/partition on your PC (including removable media like a DVD) so you may get 40 results (ordered by Drive, Size) if you have four drives/partitions on your PC. You can also see the top 5, 20 etc. files by changing first 10 to first 5 or first 20.
Create the Script
To do this, open notepad, press WinKey + R, type notepad, and press Enter.
Copy the script and you will end with something similar to this:
To force Notepad to save the file with a extension different from txt you have to use the hyphens as you see in the next picture.
Running the Script
Now if you double click over the file you will get something like this.
You will have to wait for the results, remember that the time need it by the utility is proportional to the number of files in the system.
The size is in GB. So, what are you waiting to know what are the files consuming your hard disks?
About Angel Luis
I am an Engineer of Telecommunications that love computers. My first computer was a Commodore 16kb, about 25 years ago and since then I am always fighting computers problems. Please visit my entries and ask me about whatever problem you have, I will be pleased to help you. My email is discoveryourpc [at] gmail [dot] com. You can follow me on twitter @agenlu or read my blog www.discoveryourpc.net
- Web
- |
- More Posts (48)
Great script. Takes a little long to receive the results but works good none the less.
Is there anyway to sort the results into descending size order?
Very nice, thank you.
Thank Sintax
The results are sort into descendig order in the same drive.
It is incredible that powershell can do this things with only 1 sentence.
Thanks for the comment.
Strange, the first time i ran it it didnt seem to have an order. Just re-ran it and it's sorted it correctly (as the script specifies too)…..
Thanks for the reply Angel ;)
Is there a way of running this on mapped network drives?
Right now it will do in mapped network.
Thanks
how can i take this script and have it email me the output ? I have the email piece down but when i put the script in for the body it fails
It’s a nice idea, but not being able to see exactly where the files are located (DirectoryName column isn’t wide enough), makes finding the files later much more work than it should be. Thank God that Windows 7’s search feature isn’t as useless as it was in XP
Thanks. Maybe I can change that in other version
Thanks. It was very useful.
“An empty pipe element is not allowed”.
Could you people PLEASE stop posting nonworking code?!?!?!
Nice one. Post more scripts with errors in them, will you?