Take the 2-minute tour ×
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 - recursive -. I Have to do this every month so I want to make a powershell script to doit, Any Help?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

I asked the same question in stackoverflow and I get this excelent 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 ill 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 JaredPad

share|improve this answer

Check this post out.

share|improve this answer

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.