I'm trying to run a script in background from a main script, the command is :
Start-Job -Name "Job Name" -File "Child script path" `
-ArgumentList Param1, ..., Param6.
There are 6 parameters, the first one is an array, the second a string, 3,4 and 5 are credentials and the last one a string.
If I call the second script like ( & "script path" ), it works well.
If I call the second script with Start-ThreadJob by adding the option -StreamingHost $Host after the option -Name, I got in the console a parameter's request for a command inside the second script, as it was not receiving the parameters given by the script calling Start-ThreadJob.
Any idea what I'm doing wrongly ?
DraKKarD
I tried :
Start-Job -Name "Job Name" -File "Child script path" -ArgumentList Param1, ..., Param6
=> Doesn't work
Start-ThreadJob -Name "Job Name" -StreamingHost $Host -File "Child script path" -ArgumentList Param1, ..., Param6
=> Doesn't work
& "Child script path" Param1 ... Param6
=> works
The expecting result is some log files created and filed and some actions that will write in log files.
It seems like the issue is related to passing parameters to the child script when using Start-ThreadJob. When using Start-Job, the parameters are passed explicitly using the -ArgumentList parameter, but with Start-ThreadJob, the parameters are implicitly passed using the -StreamingHost parameter.
Try upper part, This should pass the parameters to the child script correctly. If you are still having issues, you need to add some debug logging to your child script to see if the parameters are being received correctly.