Piotr Stapp
Piotr Stapp

Reputation: 19830

Run powershell in new window

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?

Upvotes: 9

Views: 18192

Answers (3)

Viktor
Viktor

Reputation: 636

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"

Upvotes: 1

T-Fred
T-Fred

Reputation: 171

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

Upvotes: 12

vonPryz
vonPryz

Reputation: 24071

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.

Upvotes: 8

Related Questions