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) $fileSizeMB = [math]::Round($fileSizeBytes / 1MB, 2)
$fileSizeGB = [math]::Round($fileSizeBytes / 1GB, 2) $fileSizeGB = [math]::Round($fileSizeBytes / 1GB, 2)
return @{ return [PSCustomObject]@{
"Bytes" = $fileSizeBytes "Bytes" = $fileSizeBytes
"KB" = $fileSizeKB "KB" = $fileSizeKB
"MB" = $fileSizeMB "MB" = $fileSizeMB

View File

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