0

I want to load a series of programs and then have the PowerShell instance close afterward. This is what I have:

Start-Process -FilePath <path to chrome>
Start-Process -FilePath <path to firefox>
Start-Process -FilePath <path to vs code>

So basically, I want to run it like a batch file where it launches the listed programs and then goes away. But instead, it leaves the powershell window open and if I manually close it, VScode shuts too (the browsers stay open for some reason).

I see there's a -wait option for start-process, but I want the opposite: -nowait. Just open and go away. How can I do this? The other commands like invoke and startjob don't seem right.

2
  • How are you executing the script? Commented Apr 5, 2022 at 20:05
  • 1
    Can you give more details, ideally a minimal reproducible example for us to try and reproduce? Commented Apr 5, 2022 at 20:46

1 Answer 1

1

Since these are GUI applications, you don't need to worry about using
Start-Process -Wait:$False; GUI applications don't block in PowerShell (or Command Prompt) by default. You can simply run those programs with the call-operator & (technically optional to use the call-operator but it covers the path-with-spaces case):

& "\path\to\guiprogram.exe"

If you need to do this with a non-GUI application, then you would need to use
Start-Process -Wait:$False (or omit -Wait altogether since Start-Process doesn't block by default) to continue executing:

Start-Process -Wait:$False "\path\to\program.exe"
Start-Process "\path\to\program.exe"

-SwitchParameter:$Value syntax allows you to set the explicit value of [switch] parameters. Usually the switch parameter is implicitly managed. It is in an "on (true)" state if provided, and an "off (false)" state when omitted.

However, you can explicitly set the value of a switch parameter by suffixing the parameter with :$Value. The value's truthiness will be evaluated and the switch state will match "on" for $True and "off" for $False.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.