#powershell Start-Job -ArgumentList Bug?

Irrespective of the position of -ArgumentList, including the intentional placement at the end of the statement per documentation for Start-Job, a string array will be treated as a single string object when passed to this cmdlet using the aforementioned parameter:

$arr = "a","b","c","d"
Start-Job -ScriptBlock {
param($a) $items = @(); $a | % { $items += $_; }; $items; } -ArgumentList $arr
$result = Receive-Job -id 2

This apparent bug continues to exist in the latest version of Windows PowerShell 5.1x. The workaround is to explicitly mark the argument as an array against the -ArgumentList parameter as illustrated:

-ArgumentList (,$arr)

(even though $arr is already an array of string objects itself)

Leave a Reply