A few days ago, one of my PowerShell scripts started returning wrong values. I think it boils down to this example:
# ArrListJob.ps1
$arr = @();
foreach ($i in 1..10) {
$arr += $i;
}
$obj = New-Object -Type System.Object
Add-Member -InputObject $obj -MemberType NoteProperty -Name Members -Value $arr;
$obj;
When I run this script, everything works fine:
> $foo = .\ArrListJob.ps1> $foo.Members.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array
But when I let this script run via a Job, I get this result:
> Start-Job -FilePath .\ArrListJob.ps1> $bar = Receive-Job Job2> $bar.Members.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ArrayList System.Object
In my real script, I had a loop that wrote the contents of the returned array, but now returns instead "System.Collection.ArrayList". The behaviour changed between 2013-01-02 and 2013-01-03, after installing a few Windows Updates, including fixes for .Net.
The script itself was not changed for some time.
Is all this a bug or a feature? I wouldn't expect the Job framework to mangle datatypes. Of course I can fix the handling of the return value in my real script, but then it would break in case I'd use it directly and not via a Job.
One more thing: When returning only the array, i.e. without enclosing it in a object, the correct datatype is kept.