How to select a value of “measure-object” directly? (powershell)

六月ゝ 毕业季﹏ 提交于 2019-12-13 02:24:03

问题


I am wondering about something. Not very important, but I am curious now...

Let's say we have a array:

PS C:\> $array
3
1129
1063
1139
1299
4446
1135
1096
1216
1075

And now we want to have the average of the values above. So I use Measure-Object:

PS C:\> $array | Measure-Object -Average | select Average

Average
-------
1360,1

okay. That's nice. But what if I only want to select the value, without getting some kind of "table" with the column name "average". I only want to have the value "1360,1" like a String or something.

I only know this way:

PS C:\> $tmp = $array | Measure-Object -Average | select Average

PS C:\> $tmp.Average
1360,1

So this works, but in this way I need a temporary variable which is not really needed... I think there must be an other easy way to get this in one line.

But I don't get it... sry! Can you help?


回答1:


this:

$tmp = $array | Measure-Object -Average | select -expand Average

or this:

$tmp = ($array | Measure-Object -Average).average


来源:https://stackoverflow.com/questions/26097224/how-to-select-a-value-of-measure-object-directly-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!