I have a powershell script running steps such as
$stuffFromAPI = $resultsFromAPI.inputs.Stuff | ConvertFrom-Json
$objectFromAPIStuff = $stuffFromAPI.item[0] #ipAddress = 127.0.0.1
$newStuff = @()
$tempStuff = $null
$condition = "yup"
$IPAddress = "10.0.0.1"
if($condtion -eq "yup")
{
$tempStuff = $objectFromAPIStuff
$tempStuff.ipAddress = $IPAddress
$newBindings+=$tempStuff
}
Write-Host $tempStuff.ipAddress
Write-Host $objectFromAPIStuff.ipAddress
Write-Host $stuffFromAPI.item[0].ipAddress
The output will be
10.0.0.1
10.0.0.1
10.0.0.1
why is $objectFromAPIStuff and even deeper $stuffFromAPI.item[0] inheriting the changed values of $tempStuff
There seems to be some link between them in memory. I have closed powershell ISE and reopened it, and I have even restarted my computer thinking something was just cached weird in powershell ISE