PowerShell Add a key value pair to an existing hash table


Example

An example, to add a "Key2" key with a value of "Value2" to the hash table, using the addition operator:

$hashTable = @{
    Key1 = 'Value1'
}
$hashTable += @{Key2 = 'Value2'}
$hashTable

#Output

Name                           Value
----                           -----
Key1                           Value1
Key2                           Value2

An example, to add a "Key2" key with a value of "Value2" to the hash table using the Add method:

$hashTable = @{
    Key1 = 'Value1'
}
$hashTable.Add("Key2", "Value2")
$hashTable

#Output

Name                           Value
----                           -----
Key1                           Value1
Key2                           Value2