modified: functions/Get-FileSize.ps1

modified:   functions/Get-ObjectCount.ps1
This commit is contained in:
Tomasz Kostrzewa 2024-03-05 23:37:54 +01:00
parent 566c2a3e97
commit 352e574c7d
2 changed files with 28 additions and 18 deletions

View File

@ -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

View File

@ -1,21 +1,31 @@
# gitea.RdzeN.net
#
# Get Object Count.
function Get-ObjectCount {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[switch]$Recurse
[switch]$Recurse,
[switch]$IncludeSize
)
$items = Get-ChildItem $Path -Recurse:$Recurse
$count = $items.Count
return $count
}
$objects = $null
if ($Recurse) {
Write-Host "Liczba obiektów w katalogu '$folderPath' i podkatalogach: $objectCount"
$objects = Get-ChildItem -Path $Path -Recurse
} else {
Write-Host "Liczba obiektów w katalogu '$folderPath': $objectCount"
$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"
}
}