How can I find the size of a folder using 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
{
 param([string]$pth)
 "{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

It's on the Microsoft Technet site here

input:

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

output:

Count    : 58
Average  :
Sum      : 1244611
Maximum  :
Minimum  :
Property : length

Tags:

Powershell