I am trying to understand why in the following example the script-block returning a List-object returns null. Eventhough with other types it works perfectly fine.
$s1 = {
param($string);
$list = [System.Collections.Generic.List[object]]::new();
return $list;
}
$s2 = {
param($string);
return 'test';
}
$r1 = (Invoke-Command -ScriptBlock ($s1) -ArgumentList('something'));
$r2 = (Invoke-Command -ScriptBlock ($s2) -ArgumentList('something'));
write-host ($null -eq $r1); # True
write-host ($null -eq $r2); # False
write-host ($r1); # <empty>
write-host ($r2); # test
The result from the above snippet is:
True
False
test
I would expect:
False
False
System.Collections.Generic.List`1[System.Object]
test
Can somebody help me understand why the $s1 scriptblock would return $null?
return ,$list;