Last active
August 7, 2026 06:50
-
-
Save Depechie/150fedc3c5fa684573b47e4403fcdf3b to your computer and use it in GitHub Desktop.
FolderSize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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