Powershell初学者。
在看这个问题的时候:Powershell -搜索目录-为每个目录找到特定的扩展名和总文件,我在另一个网站上遇到了一些PS,这对回答所提出的问题有一点帮助。下面是这个Powershell的一小部分:
Write-Host "Total Size of *.$Extension files: $('{0:N2}' -f (($Files | Measure-Object length -Sum).Sum / 1mb))MB`n`n"
从其他网页运行PS(总共)。(不只是上面引用的行)我得到了所需的结果,表明所有扩展查询的总大小。这很好,但我需要帮助来理解上面引用的这句话。我可以看到这是在做文件大小的加法,但是…
- ('{0:N2}'这是什么意思?
- 第二个"求和"函数是什么?(.Sum) ?
提前感谢。
('{0:N2}'这是什么意思?
这是正常的PS格式,详见此链接
https://devblogs.microsoft.com/scripting/powertip-formatting-numeric-output-using-powershell
https://devblogs.microsoft.com/scripting/use-powershell-and-conditional-formatting-to-format-numbers
第二个"求和"函数是什么?(.Sum) ?
要返回的最终值。它被称为using。parameter方法,用于获取一个特定的属性值。
简单的例子:
(Get-ChildItem).FullName
参见:
https://learn.microsoft.com/en us/powershell/module/microsoft.powershell.core/about/about_properties?view=powershell - 7.2
所以,不是你所发布的唯一的。这些都是正常的基本/中级PS函数调用,具有格式化的输出。
所有这些都在您的系统和MS docs站点上的PS帮助文件中通过示例显示。
https://learn.microsoft.com/en - us/powershell/module/microsoft.powershell.utility/measure object?view=powershell - 7.2