2

I know this is a strange use case but I need this to execute like this in a new process and be a single line. It has taken me a long time to get to this place. I've been tearing my hair out for hours over this... Please HELP!

This command works in powershell and cmd:

powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file C:\Temp\Test.ps1').Id"

This command works in powershell but not in cmd (can't find the file):

powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file `"C:\Temp\Test.ps1`"').Id"

And when I add a space to the filename it can't find the file in PowerShell or cmd (the file does exist):

powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file `"C:\Temp\Test 1.ps1`"').Id"
LorneCash
  • 1,446
  • 2
  • 16
  • 30
  • I'm using a script that get's process id's directly and then in cmd/posh you can use `powershell -command "C:\Temp\Test.ps1"` and it appears to work both ways for me and both with and without a space in the script name. Are you able to modify the "Test.ps1" script that you are trying to call? Could you add the contents of "Test 1.ps1" to the body of your question? – Andrew Ryan Davis Sep 21 '20 at 23:42
  • In your CMD file, use "^" instead of the backtick to escape. – shadow2020 Sep 22 '20 at 00:00
  • Does this answer your question? [Is there a way to escape quotes in ripgrep for MS Windows (Powershell or CMD)?](https://stackoverflow.com/questions/59569846/is-there-a-way-to-escape-quotes-in-ripgrep-for-ms-windows-powershell-or-cmd) – iRon Sep 22 '20 at 06:32
  • Unfortunately none of that helps – LorneCash Sep 26 '20 at 03:00

1 Answers1

0

You can directly run it from Command Prompt:

start "" powershell -file "C:\Temp\test.ps1"

This will launch the process in a new window.

Wasif
  • 14,755
  • 3
  • 14
  • 34
  • Unfortunately that doesn't help me. I need it to work from PowerShell and be double embedded like the examples in my question. – LorneCash Sep 26 '20 at 02:49