Powershell:如何从多维数组中获取单列?

Gre*_*SAT 4 powershell multidimensional-array

是否有函数、方法或语言结构允许从 Powershell 中的多维数组中检索单列?

$my_array = @()
$my_array += ,@(1,2,3)
$my_array += ,@(4,5,6)
$my_array += ,@(7,8,9)

# I currently use that, and I want to find a better way:
foreach ($line in $my_array) {
    [array]$single_column += $line[1]    # fetch column 1
}
# now $single_column contains only 2 and 5 and 8
Run Code Online (Sandbox Code Playgroud)

我的最终目标是从一列中找到不重复的值。

Bar*_*ekB 5

抱歉,我认为这样的事情不存在。我会选择:

@($my_array | foreach { $_[1] })
Run Code Online (Sandbox Code Playgroud)

为了快速找到唯一值,我倾向于使用哈希表键 hack:

$UniqueArray = @($my_array | foreach -Begin { 
    $unique = @{} 
} -Process { 
    $unique.($_[1]) = $null
} -End { 
    $unique.Keys 
})
Run Code Online (Sandbox Code Playgroud)

显然它有其局限性...