Está en la página 1de 1

--------------------------------

Muestra carpetas y subcarpetas


---------------------------------
$carpetaPrincipal = "\\Limads02\nas\LimNas2023"
$subcarpetas = Get-ChildItem -Path $carpetaPrincipal -Directory -Recurse
$resultados = @()
foreach ($subcarpeta in $subcarpetas) {
# Obtener el tamaño de la subcarpeta y convertirlo a MB
$tamañoMB = (Get-ChildItem -Path $subcarpeta.FullName -Recurse | Measure-Object
-Property Length -Sum).Sum / 1MB
$objeto = New-Object -TypeName PSObject
$objeto | Add-Member -MemberType NoteProperty -Name "Subcarpeta" -Value
$subcarpeta.FullName
$objeto | Add-Member -MemberType NoteProperty -Name "Tamaño (MB)" -Value
$tamañoMB
$resultados += $objeto
}
$resultados | Export-Csv -Path "C:\tamaño\folder-size.csv" -NoTypeInformation

---------------------------------------------

---------------------------------
Muestra carpetas segun el tamaño del mismo, ya sea MB, KB, GB
----------------------------------------------------
$carpetaPrincipal = "\\Limads02\nas\LimNas2023"
$subcarpetas = Get-ChildItem -Path $carpetaPrincipal -Directory
$resultados = @()

foreach ($subcarpeta in $subcarpetas) {


$folderSize = Get-ChildItem -Path $subcarpeta.FullName -File -Recurse |
Measure-Object -Property Length -Sum
$tamañoBytes = $folderSize.Sum

if ($tamañoBytes -ge 1GB) {


$tamaño = "{0:N2}" -f ($tamañoBytes / 1GB)
$unidad = "GB"
} elseif ($tamañoBytes -ge 1MB) {
$tamaño = "{0:N2}" -f ($tamañoBytes / 1MB)
$unidad = "MB"
} elseif ($tamañoBytes -ge 1KB) {
$tamaño = "{0:N2}" -f ($tamañoBytes / 1KB)
$unidad = "KB"
} else {
$tamaño = $tamañoBytes
$unidad = "Bytes"
}

$objeto = New-Object -TypeName PSObject


$objeto | Add-Member -MemberType NoteProperty -Name "Carpeta" -Value
$subcarpeta.FullName
$objeto | Add-Member -MemberType NoteProperty -Name "Tamaño" -Value "$tamaño
$unidad"
$resultados += $objeto
}

$resultados | Export-Csv -Path "C:\tamaño\carpetas.csv" -NoTypeInformation

También podría gustarte