diff --git a/functions/Get-FileSize.ps1 b/functions/Get-FileSize.ps1 index 77a719d..9edf968 100644 --- a/functions/Get-FileSize.ps1 +++ b/functions/Get-FileSize.ps1 @@ -14,7 +14,7 @@ function Get-FileSize { $fileSizeMB = [math]::Round($fileSizeBytes / 1MB, 2) $fileSizeGB = [math]::Round($fileSizeBytes / 1GB, 2) - return @{ + return [PSCustomObject]@{ "Bytes" = $fileSizeBytes "KB" = $fileSizeKB "MB" = $fileSizeMB diff --git a/functions/Get-ObjectCount.ps1 b/functions/Get-ObjectCount.ps1 index 8b43ac6..fd3ed08 100644 --- a/functions/Get-ObjectCount.ps1 +++ b/functions/Get-ObjectCount.ps1 @@ -1,21 +1,31 @@ -# gitea.RdzeN.net -# -# Get Object Count. - function Get-ObjectCount { - param ( + [CmdletBinding()] + param( + [Parameter(Mandatory = $true)] [string]$Path, - [switch]$Recurse + [switch]$Recurse, + [switch]$IncludeSize ) - - $items = Get-ChildItem $Path -Recurse:$Recurse - $count = $items.Count - - return $count -} - -if ($Recurse) { - Write-Host "Liczba obiektów w katalogu '$folderPath' i podkatalogach: $objectCount" -} else { - Write-Host "Liczba obiektów w katalogu '$folderPath': $objectCount" + + $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" + } } \ No newline at end of file