Skip to content

Instantly share code, notes, and snippets.

@ziyan0302
Last active July 11, 2024 08:51
Show Gist options
  • Save ziyan0302/1e36361ae13432a2dff7757ab3d58fa3 to your computer and use it in GitHub Desktop.
Save ziyan0302/1e36361ae13432a2dff7757ab3d58fa3 to your computer and use it in GitHub Desktop.
show the size of the folders in current location
# 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