Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to get the size of a directory, recursively. I have to do this every month or so. I want to make a powershell script to do it.

share|improve this question
up vote 4 down vote accepted

I asked the same question in stackoverflow and I get this excellent answer:

function Get-DirectorySize() {
  param ([string]$root = $(resolve-path .))
  gci -re $root |
    ?{ -not $_.PSIsContainer } | 
    measure-object -sum -property Length

This actually produces a bit of a summary object which will include the count of items. You can just grab the Sum property though and that will be the sum of the lengths.

$sum = (Get-DirectorySize "Some\File\Path").Sum

Thanks to JaredPad for the answer.

share|improve this answer

Check this post out.

share|improve this answer

Your Answer


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.