I know that there is that little -noexit
switch for PowerShell.
Is there anyway of staying in the shell without using that switch?
In other words, I want a script command(s) that executes then leaves the shell open.
So, let's check out how you can 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.
There are a couple of options to run a PowerShell script. The most convenient way is to simply right-click the file and choose Run with PowerShell. But this method comes with a downside. By default, most PowerShell scripts will close the PowerShell window automatically when the script is done.
Global Fix: Change your registry key by adding the -NoExit switch to always leave the PowerShell Console window open after the script finishes running.
You basically have 3 options to prevent the PowerShell Console window from closing, that I describe in more detail on my blog post.
PowerShell -NoExit "C:\SomeFolder\SomeScript.ps1"
Read-Host -Prompt "Press Enter to exit"
See my blog for more information on which registry keys to modify.
Sounds like you are looking for option #1 or #3.
This script will not exit if you run it without arguments, e.g. by double-clicking on it:
param($Work) # restart PowerShell with -noexit, the same script, and 1 if (!$Work) { powershell -noexit -file $MyInvocation.MyCommand.Path 1 return } # now the script does something # this script just outputs this: 'I am not exiting'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With