Calculate Total Folder Size

by Jun 1, 2011

Here is a useful function that you can use to calculate the total size of a folder:

function Get-FolderSize($path) {
  Get-ChildItem $path -Recurse -ea 0 -Force | 
    Measure-Object -Property Length -Sum | 
    Select-Object -ExpandProperty Sum
}

For example, if you want to know how much space your profile folder consumes, you can try this:

Get-FolderSize $home

 

It may take some time for the function to complete because it recursively visits all folders and sums up all file sizes.

 

Twitter This Tip!
ReTweet this Tip!