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?


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
 "{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
  • 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
  • 2
    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 Aug 12 '13 at 21:34
  • 1
    +1 Whoa didn't know that trick. Fascinating :)
    – nixda
    Aug 12 '13 at 21:46
  • 2
    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. Aug 13 '13 at 14:49

It's on the Microsoft Technet site here


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


Count    : 58
Average  :
Sum      : 1244611
Maximum  :
Minimum  :
Property : length
  • 1
    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? 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. Aug 13 '13 at 10:39

Others already posted great answers. Just in case anyone needs a more compact version you can use

ls path/ -r | measure length -s

which is a short form for @50-3's answer:

Get-ChildItem path/ -recurse | Measure-Object -property length -sum

To get output in MB use @Darian Everett's approach:

(ls path/ -r | measure length -s).sum/1mb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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