Powershell 之批量獲取文件大小

$startFolder = "D:\"
$colItems = (Get-ChildItem $startFolder  | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
foreach ($i in $colItems)
{
    $subFolderItems = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum)
    $FileSize="{0:N2}" -f ($subFolderItems.sum / 1GB)
    $Unit='GB'
    if($FileSize -lt 1)
    {
        $FileSize="{0:N2}" -f ($subFolderItems.sum / 1MB)
        $Unit='MB'
    }
    write-host $i.FullName  ' -- '  $FileSize  $Unit -fore green
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章