Say I have the following code:
$roles = @("first", "second", "third")
$roles = $roles | Where-Object {$_ -ne "second"}
$roles += "last"
$roles
This will result in the following output:
first
third
last
Just what I would expect. But if I take out the "thrid"
element of the array, then it performs oddly. Here is the code I run (in VS Code):
$roles = @("first", "second")
$roles = $roles | Where-Object {$_ -ne "second"}
$roles += "last"
$roles
This results in the following:
firstlast
(all on one line)
Is Powershell changing my variable to be a string when I pull out the second to last array? If so, how do I stop it from doing that? If not, what is going on here?
Why is my array all of a sudden working like a string?