PowerShell:在没有ForEach和GetEnumerator的情况下访问密钥名称

时间:2018-03-21 17:09:55

标签: powershell hashtable

我的 OrderedDictionaryKeyCollection 包含以下值:

[0] = "Alpha"
[1] = "Bravo"
[2] = "Charlie"
[3] = "Delta"
[4] = "Echo"

如何在不使用 ForEach GetEnumerator 的情况下直接访问键[2] 值(" Charlie")?

1 个答案:

答案 0 :(得分:1)

您可以使用Select-Object -Index

$OrderedDictionary = [ordered]@{
  Alpha   = ""
  Bravo   = ""
  Charlie = ""
  Delta   = ""
  Echo    = ""
}
$SecondKey = $OrderedDictionary.Keys |Select -Index 2