powershell獲取windows子文件夾的大小
阿新 • • 發佈:2018-11-21
art measure reac name ont con windows unit sub
1 $startFolder = "E:\Migration\" 2 $colItems = (Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object) 3 foreach ($i in $colItems) 4 { 5 $subFolderItems = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum) 6 $FileSize="{0:N2}" -f ($subFolderItems.sum / 1GB) 7 $Unit=‘GB‘ 8 if($FileSize -lt 1) 9 { 10 $FileSize="{0:N2}" -f ($subFolderItems.sum / 1MB) 11 $Unit=‘MB‘ 12 } 13 write-host $i.FullName ‘ -- ‘ $FileSize $Unit -fore green 14 }
計算速度很快,只需修改$startFolder變量即可。
powershell獲取windows子文件夾的大小