How to keep the shell window open after running a PowerShell script?

powershell start-process keep window open
powershell keep window open on error
close powershell window after script runs
prevent user from closing powershell window
keep shell window open
run powershell script as administrator
how to run powershell script
powershell exit script without closing window

I have a very short PowerShell script that connects to a server and imports the AD module. I'd like to run the script simply by double clicking, but I'm afraid the window immediately closes after the last line.

How can I sort this out?

You basically have 3 options to prevent the PowerShell Console window from closing, that I describe in more detail on my blog post.

  1. One-time Fix: Run your script from the PowerShell Console, or launch the PowerShell process using the -NoExit switch. e.g. PowerShell -NoExit "C:\SomeFolder\SomeScript.ps1"
  2. Per-script Fix: Add a prompt for input to the end of your script file. e.g. Read-Host -Prompt "Press Enter to exit"
  3. Global Fix: Change your registry key to always leave the PowerShell Console window open after the script finishes running.

See my blog for more information on which registry keys to modify.

Keep PowerShell Console Window Open After Script Finishes , Keep PowerShell Console Window Open After Script Finishes Running When running a script by double-clicking it, or by right-clicking it and For example: PowerShell -NoExit “C:\SomeFolder\MyPowerShellScript.ps1”  In other words, with this script we aren’t directly running Ipconfig; instead, we’re running an instance of the command shell, and passing that instance several parameters. The first such parameter is /k; this parameter tells the command shell to do whatever we ask it to and then remain open. (We’ve been told that the k is short for keep

Errr... I should have known:

powershell -noexit <path\script> 

and that's all there's to it :)

Powershell Start-Process, how-to-keep-the-shell-window-open-after-running-a-powershell-script. One-​time Fix: Run your script from the PowerShell Console, or launch  Search for Windows PowerShell ISE, right-click the top result, and select the Run as administrator option. Click on File menu. Select the New option to create a new empty .ps1 file.

The solution below prevents the script from closing when running Powershell ISE and allows the script to close otherwise.

# If running in the console, wait for input before closing.
if ($Host.Name -eq "ConsoleHost")
{
    Write-Host "Press any key to continue..."
    $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}

How to stop PowerShell from closing after running a script, PowerShell is both a command-line shell and a scripting language. for keeping a PowerShell window open after the script finishes running. Global Fix: Change your registry key by adding the -NoExit switch to always leave the PowerShell Console window open after the script finishes running. Registry Key: HKEY_CLASSES_ROOT\Applications\powershell.exe\shell\open\command Description: Key used when you right-click a .ps1 file and choose Open With -> Windows PowerShell.

[SOLVED] Keep a PS Window open after script, You create a file called 'execute.ps1' on the desktop. I'd like to run a powershell script and have the window stay open after it's finished running. It will pull the session into your own console so that it looks like a normal shell and operates  Answers: If you want to run your script from a desktop shortcut, right click your python file and select Send to|Desktop (create shortcut). Then right click the shortcut and select Properties. On the Shortcut tab select the Target: text box and add cmd /k in front of the path and click OK.

Keep your PowerShell script open when executed, You may want to execute a script, by rightclicking the script and select 'Run with PowerShell', and leave the shell open when its finished… that  You may want to use screen to run the command. You can then reattach to the session after the command completes. Alternatively, just run the command in the background some_program with its arguments&. This will leave you the ability to rerun the command and get the status of the commmand once it is done.

Keep PowerShell output window open - Help & Support, But the window closes as soon as script is called so you can't see the How to keep the shell window open after running a PowerShell script? Keep your PowerShell script open when executed Whenever you execute a PowerShell script it will run and do its thing, but afterwards it will close PowerShell. Only when you already have a prompt or scripting editor open and execute the script from there, PowerShell will remain open.

Comments
  • Related (duplicate): How to get PowerShell to keep a command window open?
  • OPs answer also works as per-script fix: wrap your script with a powershell -NoExit -Command { <The script to actually run> } Enables user to start the script via UI and see the results without editing registry keys
  • @IgorGanapolsky The problem might be that you are appending -NoExit after the script path, it needs to go before. I think if it is after it passes it as an argument to the script instead of powershell.exe.