PowerShell: Join Hashtables

By Xah Lee. Date: . Last updated: .

Join Hashtables

$aa = [ordered] @{"a" = 1; "b" = 2; }
$bb = [ordered] @{"c" = 3; "d" = 4; }
$cc = $aa + $bb
Write-Host $cc
# [a, 1] [b, 2] [c, 3] [d, 4]

if key exist, error.

$aa = [ordered] @{"a" = 1; "b" = 2; }
$bb = [ordered] @{"b" = 99; }
$cc = $aa + $bb
Write-Host $cc
# OperationStopped: Item has already been added. Key in dictionary: 'b'  Key being added: 'b'

PowerShell Hashtable, Dictionary