matekus
matekus

Reputation: 788

PowerShell: Accessing Key name without ForEach and GetEnumerator

I have an OrderedDictionaryKeyCollection comprising the following values:

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

How do I access Key[2] value directly ("Charlie") without using ForEach and GetEnumerator?

Upvotes: 0

Views: 282

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

You can use Select-Object -Index:

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

Upvotes: 2

Related Questions