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.
Hashtables are important in PowerShell. They are used to create custom objects, to pass parameters into commands, to create custom properties using Select-Object
, and as the type for values assigned to parameter values of many different commands, among other things.
The following command may be used to find commands that accept a Hashtable as a parameter type:
Get-Command -ParameterType Hashtable
This topic explores creating a Hashtable, selecting elements, enumerating all values in a Hashtable, and adding and removing elements.
Creating a Hashtable
An empty Hashtable is created in the same manner as the following:
$hashtable = @{}
Alternatively, a Hashtable may be created with specific keys and...