Hello everybody.
I am new to PowerShell and I'm facing a problem, on which I could not find any hint in the web or in the documentation.
I need to launch a number of commands from the Windows (DOS) cmd-prompt, so that they run parallel / in the background, like the 'command &' in Unix. For doing this, I found the "Start-Job" cmdlet in PowerShell.
To approach this challenge step by step, I have created a file named test1.ps1 which contains exactly one line: notepad.exe.
When I start the powershell and enter 'PS C:\tmp\pwrshell> start-job .\test1.ps1' the prompt comes back and the notepad window opens as expected. PowerShell shows a status-line containing ID=1, Name=Job1, State=Running, HasMoreData=True, Location=localhost, Command=notepad.exe. Everything seems ok so far.
When I start the command out of a batch file (without putting it into the backgroud) in the format of 'c:\tmp\pwrshell> powershell -command "& {c:\tmp\pwrshell\test1.ps1}" ', I get the notepad window and the status-line exactly as above. Perfect.
Now I'm trying to start it with Start-Job 'c:\tmp\pwrshell> powershell -command "& Start-Job{c:\tmp\pwrshell\test1.ps1}" ', I get the same status-line but no notepad opens. I have tried all possible forms of syntax I could find (with '{' and without, with '&' and without and so on)
Asking the PowerShell -help, it says :
-Command Executes the specified commands (and any parameters) as though they were typed at the Windows PowerShell command prompt, and then exits, unless NoExit is specified. The value of Command can be "-", a string. or a script block.
So what am I doing wrong? I appreciate every hint.
Thank you very much!
Thomas
No one? No idea? Maybe the question is not interesting enough? Or too basic?
Thank you
if you just want to launch off a number of batch files or console commands, you can use Start-Process. It will then add a new window for each console command, thus allowing them to run async rather than sync which is the default when they all share the same console.
Hi Tobias.
This is exactly what I'm looking for.
Thank you very much