Naveen
Naveen

Reputation: 322

How to pass Multiple Variables as Arguments to a Script using Start-job

How to pass Multiple Variables as Arguments to a Script using Start-job.

  Start-Job -Name "$jobName" -filepath $TestTool -ArgumentList $compare1

how to retrieve this argument values (of $arg1 and $arg2) in a script TestTool.ps1?

Rgds Naveen

Upvotes: 9

Views: 19991

Answers (2)

Loïc MICHEL
Loïc MICHEL

Reputation: 26180

 PS>Start-Job -Name test -ArgumentList @("hello","word") -FilePath \\server\share\test.ps1

in test.ps1 just echo the $args var

   $args

result :

PS>Receive-Job test -keep
hello
word

Upvotes: 11

dstronczak
dstronczak

Reputation: 2464

http://technet.microsoft.com/en-us/library/hh849698.aspx

"Because all of the values that follow the ArgumentList parameter name are interpreted as being values of ArgumentList, the ArgumentList parameter should be the last parameter in the command."

So I guess tha something like:

... -ArgumentList $arg1 $arg2

should work?

Upvotes: 4

Related Questions