Why does the following not iterate over the elements of the System.object[]
array returned by ConvertFrom-Json
:
ConvertFrom-Json '[1, 2, 3]' | ForEach-Object {": $_"}
but this does:
(ConvertFrom-Json '[1, 2, 3]') | ForEach-Object {": $_"}
It seems to me that in the first case the whole array gets passed as a parameter to ForEach
but the reason isn't clear to me.
Update: this appears to be a bug in Powershell related to the conversion of arrays, see here and here.