Get Folder Size using PowerShell

Get Folder Size using PowerShell

August 29, 2021 PowerShell 0

Below PowerShell script helps you to get Folder size in GB’s

$excludes = @(“Program Files”,”Windows”,”Program Files (x86)”)
$startFolder = “C:\”
$colItems = Get-ChildItem $startFolder -Force  -erroraction SilentlyContinue | Where {($_.PSIsContainer) -and ($excludes -notcontains $_.Name)} | Sort-Object
foreach ($i in $colItems)
$subFolderItems = Get-ChildItem $i.FullName -recurse -force -erroraction SilentlyContinue| Where-Object {$_.PSIsContainer -eq $false}  | Measure-Object -property Length -sum | Select-Object Sum
$i.FullName + ” — ” + “{0:N2}” -f ($subFolderItems.sum / 1GB) + ” GB”


Note: Always recommend to test before using production infrastructure. try your own risk

 2,274 total views,  2 views today

Leave a Reply

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