Created
December 12, 2025 00:07
-
-
Save nbogie/3222419e7270ea15c65d174454a802ff to your computer and use it in GitHub Desktop.
powershell script to list folders and their sizes - LLM generated - not reviewed
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
| # Define the path to scan (use "." for the current directory) | |
| $PathToScan = "." | |
| Get-ChildItem -Path $PathToScan -Directory -ErrorAction SilentlyContinue | | |
| ForEach-Object { | |
| # Calculate the size of the current folder and its contents | |
| $SizeInBytes = (Get-ChildItem -Path $_.FullName -Recurse -ErrorAction SilentlyContinue | | |
| Measure-Object -Property Length -Sum).Sum | |
| # Convert bytes to Megabytes (MB) | |
| # 1 MB = 1024 * 1024 bytes | |
| $SizeInMB = $SizeInBytes / 1MB | |
| # Create a custom object to hold the name and size | |
| [PSCustomObject]@{ | |
| Folder = $_.Name | |
| SizeMB = [Math]::Round($SizeInMB, 2) | |
| } | |
| } | | |
| # Sort the results by SizeMB in descending order (largest first) | |
| Sort-Object -Property SizeMB -Descending | | |
| # Format the output table | |
| Format-Table -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment