Last active
July 11, 2024 08:51
-
-
Save ziyan0302/1e36361ae13432a2dff7757ab3d58fa3 to your computer and use it in GitHub Desktop.
show the size of the folders in current location
This file contains 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
# Get all directories in the current location | |
$folders = Get-ChildItem -Directory | |
# Iterate over each directory and calculate its size | |
foreach ($folder in $folders) { | |
$folderPath = $folder.FullName | |
$size = (Get-ChildItem -Recurse -Force $folderPath | Measure-Object -Property Length -Sum).Sum | |
$sizeMB = [math]::round($size / 1MB, 2) | |
Write-Output "Folder: $folderPath, Size: $sizeMB MB" | |
} | |
# go to Windows PowerShell (Admin) | |
# $scriptContent | Out-File -FilePath "C:\Users\UserName\GetFolderSizes.ps1" -Encoding UTF8 | |
# .\GetFolderSizes.ps1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment