PGSE Addons, PowerShell, Scripting
Leave a comment

PowerGUI Script Editor Addon: Custom menu item generator

PowerGUI Script Editor & PowerShell ISE support better extensibility. These two editors remain to be my script editors. So, I tend to port all my PowerShell ISE customizations to PGSE if such a feature isn’t available in PowerGUI. One such ISE customization I recently did was to enable custom menu item generation using GUI. You can read more about it here. While it is very easy to create addon menu items in ISE, PGSE isn’t that straight forward. So, I thought that this ISE customization should be ported to PowerGUI script Editor as well.

So, here it is. You can download this addon from PowerGUI.org at http://powergui.org/entry.jspa?externalID=3311&categoryID=387

This is how the UI looks:

Addon UI

Addon UI

The UI is pretty self-explanatory. In the options, “Menu Text”, “Menu Shortcut”, and “Script Block” are mandatory.

At present, you can add only menu items under existing top-level menus. You won’t be able to add a top-level menu such as File or Edit. See To Do.

Also, the code isn’t completely optimized. So, there is a very good chance that you will find some nasty PowerShell code inside the module.

There is no validation that happens to check if a give menu shortcut is available or not. See To Do.

Requirements

  • You need at least 2.4.0.1659 version of PowerGUI.

Steps to install

  • Download the zip file from this page
  • Unzip the contents to $env:PSModulePath

To load the module

  • Open the Script Editor
  • Select “PowerShell Libraries” from the File menu
  • Check the Add-on.PGSEMenuGen module
  • Click on OK to close the “PowerShell Libraries” dialog

OR

  • Open the Script Editor
  • Import-Module Add-on.PGSEMenuGen

Creating a New menu Item

  • Open Script Editor
  • Press Ctrl+Shift+E or Navigate to Edit Menu -> Custom Menu Item
  • In the subsequent dialog,
  • Input Menu Text (This will appear as the menu item)
  • Select a menu category. This will be the parent menu in the script editor.
  • Input Menu Shortcut key. You must use Ctrl or Alt or Shift or a combination of all these. For example, the text you enter may be like Ctrl+9. The Ctrl part of this is case sensitive.
  • Input a scriptblock that should get triggered when you select the menu item
  • Optionally, specify a icon path. This has to be 16×16 .ico file
  • Optionally, you can choose to add the resulting menu item script to your PowerShell Profile

To Do

  • Clean up the code to implement best practices.
  • Add support for Top level menu items such as items that sit side-by-side to File or Edit menus.
  • Make Menu Shortcut optional and add support to check if a short cut is available or not.
  • Add support for nested menu items. Not sure if this is possible yet.
  • Add support for intellisense in the scriptblock text box. Very long term and I don’t know how easy it is.
Filed under: PGSE Addons, PowerShell, Scripting

by

Ravikanth is a principal engineer and the lead architect for Microsoft and VMware virtualized and hybrid cloud solutions within the Infrastructure Solutions Group at Dell EMC. He is a multi-year recipient of Microsoft Most Valuable Professional (MVP) award in Windows PowerShell (CDM) and Microsoft Azure. Ravikanth is the author of Windows PowerShell Desired State Configuration Revealed (Apress) and leads Bangalore PowerShell and Bangalore IT Pro user groups. He can be seen speaking regularly at local user group events and conferences in India and abroad.