Skip to content

Instantly share code, notes, and snippets.

@Depechie
Last active August 7, 2026 06:50
Show Gist options
  • Select an option

  • Save Depechie/150fedc3c5fa684573b47e4403fcdf3b to your computer and use it in GitHub Desktop.

Select an option

Save Depechie/150fedc3c5fa684573b47e4403fcdf3b to your computer and use it in GitHub Desktop.
FolderSize
param(
[string]$Path = (Get-Location).Path
)
$totalBytes = 0
$results = Get-ChildItem -LiteralPath $Path -Directory | ForEach-Object {
$size = (Get-ChildItem -LiteralPath $_.FullName -Recurse -File -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum).Sum
$totalBytes += $size
[PSCustomObject]@{
Name = $_.Name
SizeMB = if ($size) { [math]::Round($size / 1MB, 2) } else { 0 }
SizeGB = if ($size) { [math]::Round($size / 1GB, 2) } else { 0 }
}
} | Sort-Object SizeMB -Descending
$results + [PSCustomObject]@{
Name = 'TOTAL'
SizeMB = [math]::Round($totalBytes / 1MB, 2)
SizeGB = [math]::Round($totalBytes / 1GB, 2)
} | Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment