PowerShell: Iterate Hashtable
Iterate Hashtable by Foreach Statement
$dict = [ordered] @{"a" = 1; "b" = 2; } foreach ($k in $dict.keys) { Write-Host "key is", $k , "value is", $dict[$k] } # key is a, value is 1 # key is b, value is 2
Iterate Hashtable by Cmdlet Foreach-Object
$dict = [ordered] @{"a" = 1; "b" = 2; } $dict.keys | ForEach-Object { Write-Host "key is", $_ , "value is", $dict[$_] } # key is a, value is 1 # key is b, value is 2