I need to execute powershell file, test.ps1, from test1.ps1. I am using start-job feature of powershell. In my test1.ps1, I have
$pathToFile = (Join-Path -Path $PSSCriptRoot -ChildPath "test.ps1")
$ar = $a, $b # all these variables have values assigned
Start-Job -Name job2 -ScriptBlock{& $pathToFile -fName $args[0] -lName $args[1]} -ArgumentList $ar
In my test.ps1, I have fName and lName as parameters like:
param([string]fName, [string]lName]
I keep getting the following error:
The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
The problem is here Start-Job -Name job2 -ScriptBlock{& $pathToFile -fName $args[0] -lName $args[1]} -ArgumentList $ar
But I don't seem to find the solution to resolve this issue.And Yes, I verified that $pathToFile contains exact path to test.ps1 => C:\foo\test.ps1 Thanks for any help or suggestion.