Search notes:

System.Collections.Generic.Dictionary<TKey, TValue> (class)

Note that there is no System.Collections.Dictionary type. However, there is a System.Collections.Hashtable class (which Microsoft does not recommand to use any longer).

Methods and properties

Add() Adds a new key/value pair. Compare with TryAdd()
Clear() Removes all key/value pairs.
Comparer Returns an IEqualityComparer which then can be used to check for key-equality.
ContainsKey() Checks for the existence of a specific key.
ContainsValue() Checks for the existence of a specific value.
Count Number of key/value pairs in the dictionary.
EnsureCapacity()
GetEnumerator() Returns an enumerator that can be used to iterate over all key/value pairs.
GetObjectData()
Item[] Gets or sets the value for the specified key. Throws KeyNotFoundException if key does not exist.
Keys
OnDeserialization()
Remove() Removes the given key/value pair
TrimExcess()
TryAdd()
TryGetValue()
Values

Creating a Dictionary in PowerShell

Most of the time, an ordinary PowerShell hashtable (which is created with @{…}) is sufficient if key/value pairs need to be stored in PowerShell.
However, if an explicit Dictionary<TKey, TValue> is needed, such an object can be created like so:
$dict = new-object 'System.Collections.Generic.Dictionary[String, Int]'
$dict['four'] = 4
$dict['nine'] = 9
$dict['five'] = 5

# $dict[ 7    ] ='seven' # Error: Cannot convert value "seven" to type "System.Int32" …

echo $dict['nine']
9

Iterating over a Dictionary's keys in PowerShell

The following example tries to demonstrate how it is possible to iterate over the keys of a Dictionary<TKey,TValue> object in PowerShell.
$dict = new-object 'System.Collections.Generic.Dictionary[String, String]'

$dict['Fruit'] = 'Orange'
$dict['City' ] = 'Paris'
$dict['Make' ] = 'BWM'

foreach ($key in $dict.keys) {
   "$key -> $($dict[$key])"
}
Github repository .NET-API, path: /System/Collections/Generic/Dictionary-TKey-TValue/iterate-keys-PS.ps1

Iterating over key/value pairs in PowerShell

Because a Dictionary[TKey, TValue] implements the IEnumerable<T> interface, the GetEnumerator() is implemented which allows to iterate over the dictionary's key/value pairs. In the foreach $item in … statement, the variable $item has the two properties key and value that allow to access the respective values:
$dict = new-object 'System.Collections.Generic.Dictionary[String, Int32]'

$dict['forty-two'  ] = 42
$dict['ninety-nine'] = 99
$dict['minus one'  ] = -1


foreach ($item in $dict.GetEnumerator()) {
    "{0,-11}: {1}" -f $item.key, $item.value
}
#
# forty-two  : 42
# ninety-nine: 99
# minus one  : -1
Github repository .NET-API, path: /System/Collections/Generic/Dictionary-TKey-TValue/iterate-key-value-PS.ps1

Index