Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exit PowerShell.exe inside of CMD

Tags:

powershell

cmd

In the command prompt, entering PowerShell.exe will start a PowerShell interactive prompt inside of cmd.

How can one exit this and return to cmd.exe? Neither ctrl+c, exit(), nor the break button work.

like image 527
AllTradesJack Avatar asked Mar 13 '17 22:03

AllTradesJack


People also ask

How do I close PowerShell exe?

Open a PowerShell console session, type exit , and press the Enter key. The PowerShell console will immediately close.

Can I run PowerShell from cmd?

To run scripts via the command prompt, you must first start up the PowerShell executable (powershell.exe), with the PowerShell location of C:\Program Files\WindowsPowerShell\powershell.exe and then pass the script path as a parameter to it.

How do I stop PowerShell exe from popping up?

Disable the PowerShell Startup Status on the Task Manager Press Ctrl + Shift + Esc to open the Task Manager. Navigate to the Startup tab. Right-click on the Windows PowerShell option and select Disable. Finally, close the Task Manager and restart your device.


2 Answers

Ctrl-Break works.

exit() might work, but calling functions with parentheses is not PowerShell syntax, so it's trying to use () as a function parameter, but () is not anything in PowerShell so it's that which generates the error message. exit(1) works, because (1) is a valid expression itself which evaluates to 1 so this is the same as exit 1, and this command sets the %ERRORLEVEL% return value in the cmd environment.

It's described in help about_Language_Keywords:

Exit

Causes Windows PowerShell to exit a script or a Windows PowerShell instance.

When you run 'powershell.exe -File ', you can only set the %ERRORLEVEL% variable to a value other than zero by using the exit statement.

  • help link
like image 150
TessellatingHeckler Avatar answered Nov 01 '22 20:11

TessellatingHeckler


The correct command is exit, this will exit the current PowerShell prompt and return you to cmd.exe.

like image 42
AllTradesJack Avatar answered Nov 01 '22 20:11

AllTradesJack