The quick and easy way to start another process is just to type the command in PowerShell or write it in your script, so for example:calc
Which will load the calculator app on Windows. There are times when a more complex use needs a different approach, in which case have a look at the Call Operator (&) which is documented at about_Operators | Microsoft Docs this importantly allows the execution of the contents of a variable, for example:
$curl = "D:\Dev\curl-7.59.0\bin\curl.exe" & $curl http://www.example.comThis is still a relatively simple approach, there is a more powerful and interesting alternative called Start-Process, however you do have to learn the different parameters that go with this, for example -Wait, -NoNewWindow -RedirectStandardOutput -RedirectStandardError -ArgumentList -PassThru.
It is -PassThru
, I want to give an example of:
$Result = Start-Process "CScript" -PassThru -Wait -NoNewWindow -RedirectStandardOutput $OUTPUT_FILE -RedirectStandardError $OUTPUT_ERR_FILE -ArgumentList ".\VBScript.vbs arg1 arg2" if ($Result) # This actually means "if not null" { Write-Host $Result.GetType().FullName Write-Host $Result.ExitCode }
There are a couple of other techniques for launching a process but I would suggest that the three above are the common ones that work for the vast majority of scenarios.