Individual elements may be selected by a key. As with the hashtable, two different notations are supported:
$dictionary["Computer1"] # Key reference $dictionary.Computer1 # Dot-notation
We have seen that when adding elements, types are converted. Looking back to selecting elements from a hashtable, we know the value for the key was sensitive to type. As the dictionary has a type declared for the key, it can leverage PowerShell's type conversion.
Consider a dictionary created using a number as a string for the key:
$dictionary = New-Object System.Collections.Generic.Dictionary"[String,IPAddress]" $dictionary.Add("1", "192.168.10.222") $dictionary.Add("2", "192.168.10.13")
Each of the following examples works to access the value:
$dictionary."1" $dictionary[1] $dictionary["1"]