Search code examples
powershellpowershell-5.0

How to open new console in PowerShell AND THEN execute something in it?


I'm using a zen command shown below to navigate to my project and open a new window. The first one is used for GIT'ing and general stuff for the whole solution. The second is specific to the SPA'ing and tasks specific to the front-end.

function Dev-Zen-Mrr{
  Dev-Init
  Set-Location "dev/mrr"      
  Dev-Window "web/ClientAppAutonomous/clientapp"
}

function Dev-Window{
  param([string]$path = " ")
  Start-Process PowerShell -WorkingDirectory $path
}

I would like to execute additional calls in the window that opens second. Let's say I'd like to run the following commands in it and prefer not to wear out my fingers by typing it manually each time I reopen the working environment.

code .
ng serve

Is it possible to do at all? How? What to google for?


Solution

  • Use the Start-Process -ArgumentList argument to run your commands. Include the -noexit argument to leave the new PowerShell environment open.

    Start-Process PowerShell -WorkingDirectory $path -ArgumentList "-noexit", "code .", "ng serve"