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.
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.
The while loop at the end of this trivial script prompts me for a command and executes it. It runs with the environment of the script, so it is possible to check the values of variables. Entering "exit" terminates the loop when it is executed.
I'm sure that others will be able to share some refinements, but this is a start. Regards.
I'm not aware of a command you could run in the script that would prevent the shell from exiting if it had not been invoked using the
-noexit
command.I typically use
Read-Host "Press ENTER to continue"
at the end if I don't want the shell to close. However this won't prevent the shell from closing after you press enter if it had not been started with-noexit
.Yes, just like commandline -- output:
Not to revive a 6-year-old thread or anything, but it should be noted to anyone reading that you can end your script with
if you have the registry tweak (global fix) enabled and actually want to run an automatically-closing script.
Have you tried
That will stop execution and drop them to a nested prompt. When they exit that prompt, then the script will finish and the window will close.
This script will not exit if you run it without arguments, e.g. by double-clicking on it: