i am trying to create a new job which calls a script:
Write-Output "start"
$j1 = Start-Job -ScriptBlock { Write-Output "Thread1 running"; & ${PSScriptRoot}\script.ps1 -ARG1 ${arg1} -ARG2 ${arg2}; Write-Output "Thread1 finish" }
$j1 | Wait-Job | Receive-Job
Write-Output "done"
But its not working. The error says (german): Die Benennung "\script.ps1" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und wiederholen Sie den Vorgang.
Die Benennung "\script.ps1" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und wiederholen Sie den Vorgang.
The problem is obviously in & ${PSScriptRoot}\script.ps1 -ARG1 ${arg1} -ARG2 ${arg2};
but the root path is 100% correct.
Does somebody has a Solution for my problem?
So $psscriptRoot\script.ps1
has to be string concatenated which is not there in your case. As a result, PS could not understand it and it was considering the path as C:\Users\xxx\Desktopscript.ps1
instead of C:\Users\xxx\Desktop\script.ps1
. Kindly enclose that in the double quotes:
Replace: ${PSScriptRoot}\script.ps1
with "${PSScriptRoot}\script.ps1"
Here is the output:
You should be good with the changes. Note by, that I have not worked on the argument part.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.