# # Lets get the top 5 file types by size # # First we store all the files in variable so we don't have to keep fetching them. $everything = dir c:\Windows\system32 -recurse -ea 0 # # So Here is the Goal # $everything | ?{!$_.PSIsContainer} | Group-Object Extension | select name,@{n="GroupSizeMB";e={[int]((($_.group | measure-object -sum Length).sum)/1MB)}} | sort -desc GroupSizeMB | select -first 5 # # That was very simple, but unless your familar with Powershell that line could be daunting. Lets break it down. # # First, we need to get all the files in a directory # $everything | select -first 100 # # Hmmm, it seems we have folders in there too. Need to get rid of those $everything | ?{!$_.PSIsContainer} | select -first 100 # # Now that we have all the files. We need to group them by Extension # $everything | ?{!$_.PSIsContainer} | Group-Object Extension # # The next part is a little complicated, but really all it does is creates new properties base on other values # Its what we call a Calculated Properties. Meaning they are built off other values. # $everything | ?{!$_.PSIsContainer} | Group-Object Extension | select name,@{n="GroupSizeMB";e={[int]((($_.group | measure-object -sum Length).sum)/1MB)}} # # Next we want to sort them Descending using the Property we created call GroupSizeMB # $everything | ?{!$_.PSIsContainer} | Group-Object Extension | select name,@{n="GroupSizeMB";e={[int]((($_.group | measure-object -sum Length).sum)/1MB)}} | sort -desc GroupSizeMB # # Finally we only want the top five so we can use select to only return five # $everything | ?{!$_.PSIsContainer} | Group-Object Extension | select name,@{n="GroupSizeMB";e={[int]((($_.group | measure-object -sum Length).sum)/1MB)}} | sort -desc GroupSizeMB | select -first 5 # # It was curious that we had a large amount of space being used by files with no extensions. How do we figure that out # $everything | ?{!$_.PSIsContainer} | Group-Object Extension | ?{$_.Name -match "^$"} # # To see the actual files # $everything | ?{!$_.PSIsContainer} | Group-Object Extension | ?{$_.Name -match "^$"} | %{$_.Group} | Select FullName,Length