Here I assign the value of an array to a variable, I then alter the variable, the array changes also.
$TestArray = @{ "ValueA" = "A" ; "ValueB" = "B" ; "Number" = "" }
$TestNumbers = 1..10
foreach ($number in $testnumbers) {
$results = $TestArray
$results.Number = $number
Write-Host $TestArray.Number
}
I thought that $results = $TestArray would take a copy of $TestArray but this test shows that modifying $results also changes the corresponding value in $TestArray
Can anyone help me understand this behavior?