How can I find the size of a folder using Powershell?
I want to be able to see how big a folder is (all contents, including sub-folders and their contents). I can't find a powershell command to do that, but I don't want to have to open the windows explorer every time I want to know the size. Is there a simple way to accomplish this from within Powershell?
Solution 1:
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
Solution 2:
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