问题
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