Private/Get-TechCarePathSize.ps1
|
function Get-TechCarePathSize { <# .SYNOPSIS Suma el tamano de todos los ficheros bajo una ruta. .DESCRIPTION Se usa para decirle al tecnico cuanto hay en cada carpeta ANTES de borrar, de modo que la vista previa tenga cifras y no solo nombres de carpeta. Los ficheros sin permiso de lectura se omiten en lugar de abortar la suma. #> [CmdletBinding()] [OutputType([int64])] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Path ) if (-not (Test-Path -LiteralPath $Path)) { return [int64]0 } $total = [int64]0 try { $files = Get-ChildItem -LiteralPath $Path -Recurse -Force -File -ErrorAction SilentlyContinue foreach ($file in $files) { $total += $file.Length } } catch { # Carpetas con reparse points o rutas demasiado largas: se devuelve lo # acumulado hasta el fallo, que sigue siendo util como orden de magnitud. Write-Verbose ('No se pudo recorrer por completo {0}: {1}' -f $Path, $_.Exception.Message) } return $total } |