Powershell: Get Folder Size ‘Quickly’

KB ID 0001660

Problem

Right clicking a folder and selecting properties is usually how you would see how large a folder is. Which is great, but if your folder size is HUGE (i.e. many terabytes) then this takes ages!

Solution

If you use PowerShell you can get the figure considerably quicker! Below I want to ge the size of E:\Shared;

In MegaBytes;
"{0:N2}" -f ((Get-ChildItem -path E:\Shared -recurse | Measure-Object -property length -sum ).sum /1MB) + " MB"

In GigaBytes;
"{0:N2}" -f ((Get-ChildItem -path E:\Shared -recurse | Measure-Object -property length -sum ).sum /1GB) + " GB"

In TeraBytes;
"{0:N2}" -f ((Get-ChildItem -path E:\Shared -recurse | Measure-Object -property length -sum ).sum /1TB) + " TB"

You can even save this as a ‘function’ then call it whenever you wish.

function Get-FolderSize
{
 param([string]$pth)
 "{0:N2}" -f ((gci -path $pth -recurse | measure-object -property length -sum).sum /1GB) + " GB"
}

Get Folder Size With PowerShell

 

Related Articles, References, Credits, or External Links

NA

Author: PeteLong

Share This Post On

2 Comments

  1. In the screen shot you provide the parameter name in the function is hard coded to the value E:\Shared and not the variable name defined b ythe parameter.

    Post a Reply
    • Hi Darryn yes the screenshot is incorrect 🙂

      P

      Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *