2

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.

2 Answers 2

4

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.

2

Check this post out.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .