如何选择“测量对象"的值?直接地? (电源外壳) [英] How to select a value of "measure-object" directly? (powershell)
问题描述
我想知道一些事情.不是很重要,但我现在很好奇...
I am wondering about something. Not very important, but I am curious now...
假设我们有一个数组:
PS C:\> $array
3
1129
1063
1139
1299
4446
1135
1096
1216
1075
现在,我们希望获得上述值的平均值.所以我用Measure-Object
:
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
好的.那很好.但是,如果我只想选择该值,而不用列名称为"average"的某种表",那该怎么办?我只想将值"1360,1"设为String或类似的内容.
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.
我只知道这种方式:
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?
推荐答案
此:
$tmp = $array | Measure-Object -Average | select -expand Average
或者这个:
$tmp = ($array | Measure-Object -Average).average
这篇关于如何选择“测量对象"的值?直接地? (电源外壳)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!