Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A hash table or hash map is a data structure that lets you map keys (e.g., a person’s name) to their associated values (e.g., the person’s telephone number). A hash table implements an associative array.
The @{} creates an empty hash table, similar to the @() used to create the empty array.
$h = @{}
$h.Count
0
$h.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Hashtable System.Object
Once we have an empty hash table, we can map keys and values to it. With PowerShell, we can use either the traditional approach or dot notation:
$h = @{}
$h["Item0"] = 0 # More ceremony
$h.Item1 = 1 # Notice, dot notation
$h.Item2 = 2
$h # Prints the Hash table
Name Value
---- -----
Item1 1
Item0 0
Item2 2