Search notes:

System.Collections.Hashtable (class)

A System.Collections.Hashtable object stores key/value pairs. In other programming languages, such objects are also referred to as dictionaries or associative arrays.

Derivation and interfaces

System.Collections.Hashtable derives directly from System.Object and implements System.IClonable and IDictionary.

There is no Hashtable<TKey, TValue>

Unlike many other classes in the System.Collections namespaces, there is no counterpart with the name System.Collections.Generic.Hashtable<TKey, TValue>. However, there is a System.Collections.Generic.Dictionary<TKey, TValue> class.
In fact, Microsoft recommends to use the Dictionary<TKey, TValue> class.

Using hashtables in PowerShell

Create a hashtable

In PowerShell, a hash table can be created like so:
PS: C:\> $ht = @{
  key_1 = 'foo'
  key_2 = 'bar'
  key_3 = 'baz'
}

PS: C:\> $ht.GetType().FullName
System.Collections.Hashtable

Adding a value to a hash table

PS: C:\> $ht.key_4 = 'added'

Iterating over elements

The hashtable's property keys (whose type is System.Collections.Hashtable+KeyCollection which implements System.Collections.ICollection and System.Collections.IEnumerable) provides the names of the keys in the hashtable. This allows to iterate over the key/value pairs:
$ht.keys | foreach-object { "$_ -> $($ht[$_])" }
GetEnumerator() returns a an enumerator that provides System.Collections.DictionaryEntry objects with the two properties Key (apparently aliased to Name in PowerShell) and Value:
$ht.GetEnumerator() | foreach-object { "$($_.key) -> $($_.value)" }

Using hash tables for splatting

Hash tables can be used for function parameter splatting.

See also

System.Collections.Specialized.OrderedDictionary
In PowerShell, the type accelerator for System.Collections.Hashtable is [hashtable].

Index