About hashtables
A hashtable is an associative array or an indexed array. Values in the hashtable are added with a unique key. Each key has a value associated with it; this is also known as a key-value pair. Keys cannot be duplicated within the hashtable.A hashtable is one of several collections broadly known as dictionaries. In each case, the dictionary uses a key to identify a value in the collection.Hashtables, and dictionaries in general, are incredibly widely used in PowerShell.For example, Chapter 1, Introduction to PowerShell made use of hashtables when exploring splatting.They can be used as arguments for parameters by commands such as Select-Object
, Sort-Object
, Group-Object
, Format-List
, and Format-Table
. They are also used by many others to accept generic sets of arguments.Hashtables are used repeatedly throughout this book.An empty hashtable can be created, or a set of initial values can be set.
Creating a Hashtable
An empty Hashtable is created in much the same way as an...