Preventing PowerShell Window from Disappearing

Here’s a handy tip.  If you run a PowerShell script by right-clicking a .ps1 file and selecting Run with PowerShell, a command window will appear and the script will run.  If an error is displayed, however, the window will disappear before you can read the error.

To prevent this by leaving the window visible:

  • Open the Registry Editor (regedit)
  • Navigate to HKCR\Microsoft.PowerShellScript.1\Shell\Command
  • Edit the default property by dbl-clicking on it
  • Immediately before “-Command”, add -noexit (make sure to include spaces before/after the new text)

(Default) entry should now read:

“C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -noexit “-Command” “if((Get-ExecutionPolicy ) -ne ‘AllSigned’) { Set-ExecutionPolicy -Scope Process Bypass }; & ‘%1′”

Exit Registry Editor and re-run your script.  Powershell windows will now remain open after execution.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s