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变量即可。
posted on 2018-11-21 11:59 discover_dev 阅读(1072) 评论(0) 编辑 收藏 举报