Start-RSJob with -ArgumentList parameter and param() in -scriptblock: first argument is lost
Closed this issue · 1 comments
I've just tested this against 1.7.3.9 and 1.7.3.11. It looks like the first argument passed to start-rsjob in the -argumentList parameter is not passed through to the param block of the scriptblock. I tested with simple strings and with synchronized hashtables as shown below.
Here's a simple test with string variables:
$string1 = 'decoy1'
$string2 = 'useable1'
$string3 = 'useable2'
Start-RSJob -Name first -ArgumentList $string1,$string2,$string3 -ScriptBlock {
param(
#$string1
#,
$string2
,
$string3
)
"string1 is $string1"
"String2 is $string2"
"String3 is $string3"
}
Wait-RSJob -Name first
Receive-RSJob -Name first
Remove-RSJob -Name first
Here's a bit more complex test with synchronized hashtables (I wasn't certain at first if it was only the first element in the argumentlist array that was affected or not so I got a bit carried away here):
$hashtable1 = [hashtable]::Synchronized(@{})
$hashtable2 = [hashtable]::Synchronized(@{})
$hashtable3 = [hashtable]::Synchronized(@{})
$hashtable4 = [hashtable]::Synchronized(@{})
$decoystring1 = 'decoy1'
Start-RSJob -Name first -ArgumentList $decoystring1,$hashtable1,$hashtable2,$hashtable3,$hashtable4 -ScriptBlock {
param(
$hashtable1,$hashtable2,$hashtable3,$hashtable4
)
[System.Threading.Monitor]::Enter($hashtable1.SyncRoot)
$hashtable1.thisis = 1
$hashtable1.decoystring = $decoystring1
[System.Threading.Monitor]::Exit($hashtable1.SyncRoot)
[System.Threading.Monitor]::Enter($hashtable2.SyncRoot)
$hashtable2.thisis = 2
[System.Threading.Monitor]::Exit($hashtable2.SyncRoot)
[System.Threading.Monitor]::Enter($hashtable3.SyncRoot)
$hashtable3.thisis = 3
[System.Threading.Monitor]::Exit($hashtable3.SyncRoot)
[System.Threading.Monitor]::Enter($hashtable4.SyncRoot)
$hashtable4.thisis = 4
[System.Threading.Monitor]::Exit($hashtable4.SyncRoot)
}
Wait-RSJob -Name first
Write-Verbose -Message "hashtable1 was hashtable$($hashtable1.thisis) in the job" -Verbose
Write-Verbose -Message "hashtable1 received $($hashtable1.decoystring) in the job" -Verbose
Write-Verbose -Message "hashtable2 was hashtable$($hashtable2.thisis) in the job" -Verbose
Write-Verbose -Message "hashtable3 was hashtable$($hashtable3.thisis) in the job" -Verbose
Write-Verbose -Message "hashtable4 was hashtable$($hashtable4.thisis) in the job" -Verbose
Remove-RSJob -Name first