我正在运行PowerShell代码来检查文件夹大小。我只是注意到结果与我在文件夹属性的Windows GUI中看到的结果不同。
PowerShell代码的一部分:
@{label="Size" ; expression={(Get-childitem "c:\windows" -recurse | measure-object length -sum).sum}}
结果不一样....?
顺便说一句,如何根据上述代码以GB为单位显示大小?
请提示!
您获得不同结果的原因是隐藏的文件和文件夹。要解决这些问题,请-Force开启Get-childitem
:
@{label="Size" ; expression={(Get-childitem -force "c:\windows" -recurse | measure-object length -sum).sum}}
要将总分为GB,只需将结果除以1Gb
,即:
@{label="Size" ; expression={(Get-childitem -force "c:\windows" -recurse | measure-object length -sum).sum/1Gb}}
或将其舍入到小数点后一位:
@{label="Size" ; expression={[math]::round(((Get-childitem -force "c:\windows" -recurse | measure-object length -sum).sum/1Gb),1)}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句