Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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.