PowerShell统计子文件夹大小

转自 https://www.cnblogs.com/20e8/p/9994212.html

$startFolder = "D:\test\"
$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
}
posted @ 2022-09-29 10:12  shenshu  阅读(309)  评论(0)    收藏  举报