diff --git a/File-Management-Scripts/get-overall-folder-size-with-child-items-in-mb.ps1 b/File-Management-Scripts/get-overall-folder-size-with-child-items-in-mb.ps1 index 154b0b4..ca6175c 100644 --- a/File-Management-Scripts/get-overall-folder-size-with-child-items-in-mb.ps1 +++ b/File-Management-Scripts/get-overall-folder-size-with-child-items-in-mb.ps1 @@ -8,11 +8,26 @@ $projectfolders = @( # Loop through each folder and calculate the total size foreach ($projectfolder in $projectfolders) { if (Test-Path $projectfolder) { - $folderSize = (Get-ChildItem -Path $projectfolder -Recurse | Measure-Object -Property Length -Sum).Sum + # Store Get-ChildItem results in a variable to optimize performance + $items = Get-ChildItem -Path $projectfolder -Recurse + + # Calculate total size + $folderSize = ($items | Measure-Object -Property Length -Sum).Sum $folderSizeMB = [math]::Round($folderSize / 1MB, 2) - Write-Output "Total size of $projectfolder : $folderSizeMB MB" + + # Count files and folders + $fileCount = ($items | Where-Object { -not $_.PSIsContainer }).Count + $folderCount = ($items | Where-Object { $_.PSIsContainer }).Count + + # Display information in structured format + Write-Output "Folder: $projectfolder" + Write-Output " Total size: $folderSizeMB MB" + Write-Output " Files: $fileCount" + Write-Output " Folders: $folderCount" + Write-Output "" } else { Write-Output "Folder $projectfolder does not exist." + Write-Output "" } }