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 green14 }
计算速度很快,只需修改$startFolder变量即可。