Tuesday, July 7, 2020

Get Folder Size Quickly



GET folder Size Quickly

You know how long it takes when you right-click a folder and click on properties to check its size.

Here is some PowerShell code snippet to help you on this front.

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

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

In TeraBytes;

"{0:N2}" -f ((Get-ChildItem -path C:\Data -recurse | Measure-Object -property length -sum ).sum /1TB) + " TB"

You are also writing a function. 


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

Then use the function like this.

Get-FolderSize C:\Data


No comments: