Powershell 列出指定目录下的目录大小

Powershell

$roots = @(
    "D:\oldfile",
    "D:\Private",
    "D:\Public"
)

$roots | ForEach-Object {
    Get-ChildItem $_ -Directory -ErrorAction SilentlyContinue
} | ForEach-Object {
    $size = (Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue |
        Measure-Object Length -Sum).Sum

    [PSCustomObject]@{
        Name   = $_.Name
        SizeGB = "{0:N2}" -f ($size / 1GB)
        Path   = $_.FullName
    }
} | Sort-Object {[double]$_.SizeGB} -Descending

评论已关闭。