天天看點

Powershell進行統計的功能

Powershell中Measure-Object可以對對象計數并計算數字值的最小值、最大值、總和及平均值。對于文本對象,它可以計數并計算行數、單詞數和字元數。

以D:\為例來說明:

<a href="http://281816327.blog.51cto.com/attachment/201409/8/907015_1410171243w65j.png" target="_blank"></a>

(1)計算D中檔案和檔案夾的個數;

Get-ChildItem |Measure-Object

<a href="http://281816327.blog.51cto.com/attachment/201409/8/907015_1410171260GM23.png" target="_blank"></a>

(2)計算D中檔案的大小的總和,最小,最大,平均數

Get-ChildItem |Measure-Object -Property length -Minimum -Maximum -Average -Sum

<a href="http://281816327.blog.51cto.com/attachment/201409/8/907015_1410171272JHDW.png" target="_blank"></a>

(3)計算檔案中的字元數,行數,單詞數;

Get-Content D:\powershelllog.txt |Measure-Object -Character -Line –Word

<a href="http://281816327.blog.51cto.com/attachment/201409/8/907015_1410171281ng8j.png" target="_blank"></a>

本文轉自 bannerpei 51CTO部落格,原文連結:http://blog.51cto.com/281816327/1549934,如需轉載請自行聯系原作者

繼續閱讀