9

I would like to run new powershell window with parameters. I was trying to run following:

powershell -Command "get-date"

but everything happens in same console. Is there a simple way to do this?

Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • Possible duplicate of [PowerShell launch script in new instance](https://stackoverflow.com/questions/23237473/powershell-launch-script-in-new-instance) – cbp Apr 25 '18 at 10:51

3 Answers3

12

To open a new PowerShell Window from PowerShell:

Start-Process PowerShell

Or my personal favorite:

Start-Process PowerShell -WindowStyle Maximized

Then you could typeGet-Datewithout having to deal with the -ArgumentList's tendency to close itself. I still haven't found a way to open a new PowerShell process with the -ArgumentList Parameter, without it immediately closing after it runs. For Instance:

Start-Process PowerShell -ArgumentList "Get-Date"

or simply

Start-Process PowerShell -ArgumentList Get-Date

Will Close Immediately after running the process.

In order to get it to wait before closing you could add:

Start-Process PowerShell -ArgumentList 'Get-Date; Read-Host "Press Enter"'

Since the -Wait Parameter seems to do nothing at all in this case.

FYI - PowerShell Suggested Syntax is actually:

Start-Process -FilePath "powershell.exe"

But since PowerShell is a standard Windows Application in the %SystemRoot%\system32 Environment Variables the command line(s) should recognize a simple

Powershell

Command

T-Fred
  • 171
  • 2
  • 3
  • This's more simple answer that I hope from the community. Thanks for sharing! – Benyamin Limanto Apr 03 '19 at 08:53
  • @t-fred, I was able to get the window to stay open by basically combining your two suggestions. Start a powershell process which runs powershell with the `-NoExit` arg: `Start-Process PowerShell -ArgumentList "PowerShell -NoExit 'get-date'"` #janky – th3coop Aug 24 '21 at 04:15
7

Use the start command. In a CMD prompt, try:

start powershell -noexit -command "get-date"

For Start/Run (or Win+r) prompt, try:

cmd /c start powershell -noexit -command "get-date"

The -noexit will tell Powershell to, well, not to exit. If you omit this parameter, the command will be executed and you are likely to just see a glimpse of a Powershell window. For interactive use, this is a must. For scripts it is not needed.

Edit:

start is an internal command for CMD. In Powershell it is an alias for Start-Process. These are not the same thing.

As for why the window is black, that's because the shortcut for Powershell.exe is configured to set the background blue.

vonPryz
  • 22,996
  • 7
  • 54
  • 65
1

To call a PowerShell (PS) script in a second terminal window without exiting, you can use a script similar to:

Start-Process PowerShell -ArgumentList "-noexit", "get-date"

or if you need to run another script from a specific location:

Start-Process PowerShell -ArgumentList "-noexit", "-command .\local_path\start_server.ps1"
Viktor
  • 380
  • 5
  • 14