[英]Group-Object on an array?
How to use Group-Object
on the first two columns (a, b) and (c, e) of the following array? 如何在以下数组的前两列(a,b)和(c,e)上使用Group-Object
?
$a = @('a','b','x',10),
@('a','b','y',20),
@('c','e','x',50),
@('c','e','y',30)
Group-Object
accepts anonymous calculated properties, in place of property names: Group-Object
接受匿名计算的属性,而不是属性名称:
PS C:\> $a | Group-Object @{ Expression={$_[0]} },@{ Expression = {$_[1]} }
It also accepts a ScriptBlock: 它还接受ScriptBlock:
PS C:\> $a | Group-Object {$_[0]},{$_[1]}
As long as the expression can be evaluated to a string: 只要表达式可以计算为字符串:
PS C:\> Get-Help Group-Object -Parameter Property
-Property [<Object[]>]
Specifies the properties for grouping. The objects are arranged into groups
based on the value of the specified property.
The value of the Property parameter can be a new calculated property.
To create a calculated, property, create a hash table with an Expression key
that specifies a string or script block value.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.