Script to Calculate Folder Sizes PowerShell Print

  • Script to Calculate Folder Sizes PowerShell, Script to Calculate Folder Sizes, Calculate Folder Sizes
  • 0

$volumePath = "C:\"  # Replace this with the path of the volume root you want to analyze

# Get all directories at the root of the volume
$directories = Get-ChildItem -Path $volumePath -Directory

# Calculate size for each directory
foreach ($dir in $directories) {
    $dirSize = (Get-ChildItem -Path $dir.FullName -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
    $dirSizeGB = [math]::Round($dirSize / 1GB, 2)  # Convert bytes to gigabytes
    Write-Output "$($dir.Name) - $dirSizeGB GB"
}

Was this answer helpful?

« Back