function Get-ObjectCount { [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [switch]$Recurse, [switch]$IncludeSize ) $objects = $null if ($Recurse) { $objects = Get-ChildItem -Path $Path -Recurse } else { $objects = Get-ChildItem -Path $Path } $count = $objects.Count if ($IncludeSize) { $totalSizeBytes = ($objects | Measure-Object -Property Length -Sum).Sum $totalSizeKB = [math]::Round($totalSizeBytes / 1KB, 2) $totalSizeMB = [math]::Round($totalSizeBytes / 1MB, 2) $totalSizeGB = [math]::Round($totalSizeBytes / 1GB, 2) Write-Output "Total objects: $count, Total size: $totalSizeBytes bytes ($totalSizeKB KB, $totalSizeMB MB, $totalSizeGB GB)" } else { Write-Output "Total objects: $count" } }