The use of the script block within your Start-Job seems, well, odd to me. I'm not sure why you're doing in that way, but with the example you gave it sure looks like there should be a better way to do it.
I don't think your issue is with the job so much as with your construction of the OrderedDictionary. Take the job out of it and try and just make that object the way you are now and it throws errors.
At the very least you need to insert an @
symbol after [Ordered]
.
Since you seem to be requiring some parameters and all, if it were me I'd move it into a function and then call the function from the $ret =
line like this:
$Params = [ordered]@{ "Param1" = "Value1"; "Param2" = "Value2" }
Function Quibble {
param(
[System.Collections.Specialized.OrderedDictionary]$ParamIn = $(throw "Please pass Params.")
)
Start-Job -ScriptBlock {$ParamIn} -Name "Execute" -ErrorVariable Errors -ErrorAction Stop -ArgumentList $ParamIn
}
$ret = Receive-Job $(Quibble $Params) -Wait -AutoRemoveJob
This parses without errors on my end, though I didn't actually pass real job data to it and it just basically did nothing. Obviously you will need to modify it for your needs if nothing else change the stupid function name I randomly came up with.