powershell获取windows子文件夹的大小

 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变量即可。

原文地址:https://www.cnblogs.com/20e8/p/9994212.html