Powershell Logo

Quickly get folder size (Powershell)

Today’s post is a nice quick win, it will show you how to quickly get folder size via Windows Powershell 👍

The issue:

Right clicking a folder and selecting properties is usually how you can see how large a folder is, but if your folder size is massive then this takes bloody ages! Not to mention it will only list the top level contents as a whole.

The resolution:

If you use PowerShell you quickly get folder size (overall) in the blink of an eye!

Below I want to get the size of C:\NSP;

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

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

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

Quickly get folder size
You can even pop this in a script and have it list all top level individual folders sizes:

First change to the directory you want to check and run the following command:

$colItems = Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
foreach ($i in $colItems)
{
$subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
$i.FullName + ” — ” + “{0:N2}” -f ($subFolderItems.sum / 1GB) + ” GB”
}

Quickly get folder size

Very handy if you are performing a migration and need to know individual folder sizes 👍

Get-Childitem is a very wide varied PS command, you can find more info on it here.

To get help with migrations or for anything else, feel free to get in touch. 👍

Leave a Reply