3

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!

Eccentropy
  • 444
  • 1
  • 4
  • 11

2 Answers2

5

PowerGUI Script Editor runs a couple of things on its startup: PowerShell profiles, and whatever modules/snapins you have selected.

To disable PowerShell profile invocation:

  • In PowerGUI Script Editor, go to Tools / Options / Debug options and clear the Load PowerShell profiles checkbox.

To make sure that no modules/snapins/add-ons are started:

  • In PowerGUI Script Editor, go to File / PowerShell libraries, and clear all checkboxes in the list.

Next time you start PowerGUI Script Editor it will then not run any external PowerShell code.

DSotnikov
  • 634
  • 3
  • 10
2

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.

Poshoholic
  • 136
  • 3
  • 1
    Thanks, that was it. PowerGUI says (Running) in the title bar, but it wasn't actually running my scripts. – Eccentropy Jan 21 '11 at 06:59