Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to be able to see how big a folder is (all contents, including sub-folders and their contents). I can't find a powershell command to do that, but I don't want to have to open the windows explorer every time I want to know the size. Is there a simple way to accomplish this from within Powershell?

share|improve this question

2 Answers 2

up vote 12 down vote accepted

Pretty sure I got this from a Powershell tip of the day; can't remember for sure, but I've been using it a long time and it's been very useful.

"{0:N2}" -f ((Get-ChildItem -path C:\InsertPathHere -recurse | Measure-Object -property length -sum ).sum /1MB) + " MB"

Edit: To make it easier to use (so you don't have to remember and type this whole thing out each time) you could add it to your profile as a function, like so:

function Get-Size
{
 param([string]$pth)
 "{0:n2}" -f ((gci -path $pth -recurse | measure-object -property length -sum).sum /1mb) + " mb"
}

And then use it like any command:

Get-size C:\users\administrator
share|improve this answer
1  
I'm curious, how do I add this to a PowerShell profile? Do you mean dot sourcing? (side note: code can be formatted by adding 4 blank spaces at the beginning) –  nixda Aug 12 '13 at 21:19
1  
You can . source your profile if you've made changes and don't want to restart your PS session, but it loads automatically every time you start Powershell, so you generally wouldn't do that. To create your profile for the first time, do the following: ni $profile -type f -fo Then you can open and edit your profile. To find where it is located, just type $profile into the shell and the path will be displayed. Then any function you add, such as the one above, is available like it's built in. Thanks for the code formatting tip also –  Darian Everett Aug 12 '13 at 21:34
    
+1 Whoa didn't know that trick. Fascinating :) –  nixda Aug 12 '13 at 21:46
    
what does {0:N2} do? –  soandos Aug 12 '13 at 22:52
1  
Formatting. The zero is the place-holder, the N2 means it's a number with two decimal places. –  Darian Everett Aug 13 '13 at 14:49

It's on the Microsoft Technet site here

input:

Get-ChildItem C:\Scripts -recurse | Measure-Object -property length -sum

output:

Count    : 58
Average  :
Sum      : 1244611
Maximum  :
Minimum  :
Property : length
share|improve this answer
    
This can often be pretty far off though, as you need to recursively check if the folder has sub folders. Also, what is that measurement, bits? –  AthomSfere Aug 12 '13 at 21:48
    
Correct it's bits - also forgot to include the recurse switch which I have no edited in - also note I was mainly posting to provide the technet article on performing these search found via google (powershell folder size) so OP could get a full understanding of the commands used not just the answer –  50-3 Aug 12 '13 at 22:20
    
Thanks for the updates, its a better fit now I think for the Q&A format. –  AthomSfere Aug 13 '13 at 10:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.