Opening new PowerShell Windows from PowerShell and Running Commands in them

This is mostly a post to my future self, but I hope it helps someone else too.

I am working on a blog post where I want to -

  1. launch multiple commands one after the other
  2. each command opens its own PowerShell window
  3. the window stays open after the command has finished
  4. the window can be closed easily (by pressing a button rather than typing exit or closing it with the mouse)

Here is the first way -

start pwsh { -Command "dir; pause" } ; start pwsh { -Command "dir; pause" }; start pwsh { -Command "dir; pause" }

And another -

for ($i=0; $i -lt 3; $i++)
{
   start pwsh { -Command "dir; pause" }
}
comments powered by Disqus