powergui

How to Prevent PowerGUI from Running Script on Open?


When I open any .ps1 via "Open with PowerGUI Script Editor" in Windows Explorer's context menu, PowerGUI first runs the script, then lets me edit it. Is this behaviour by design?

If I run the PowerGUI Script Editor then open the .ps1 via File | Open, it doesn't run it and lets me edit it right away (desired behaviour).

How can I: 1) prevent PowerGUI editor from first running the script when opened, and 2) use a command-line parameter to do same (to use PowerGUI as a helper app)?

Thanks!


Solution

  • Unless there is an obscure bug here, PowerGUI does not execute a script when it opens it using the "Open with PowerGUI Script Editor" context menu, nor does it execute a script when you double-click it. When you open a script this way, it simply opens it in the editor. You will see the text "Executing script..." appear in the status bar in the Script Editor, not because it is executing the script that you are opening, but because it is executing other scripts (profile, loading modules, etc). If your script is executing I would investigate to see how it is being executed, and this can be done using the $MyInvocation variable and Get-PSCallStack to pull that information.

    As for your other question, you can use a command line to get the PowerGUI Script Editor to open a script file. We have a number of partners that do this with our Script Editor. For details on the options available, see this page on our wiki http://wiki.powergui.org/index.php/Using_Editor_from_external_applications.