Script Template Add-on for PowerGUI Script Editor

As a best practice, most script authors adds a header to their scripts containing some basic information like the script name, the author and version history.

Some commercial script editors, like Ideras PowerShell Plus, contains script-templates to make this easier. PowerGUI is another commercial editor, available both in a free and Pro version. This product doesnt contain any script templates by default, however its easy to extend the product with needed functionality by building Add-ons. Ive created an add-on named Script Template, available here.

When creating a new document in the PowerGUI Script editor, the following template is automatically inserted when the Add-on is loaded:

image

The easiest way to install the Add-on is by using Tools->Find Add-ons Online:

image

Search for “script template” and then press “Install”.

If you want to customize the template you can open the file DocumentsWindowsPowerShellModulesAdd-on.ScriptTemplateAdd-on.ScriptTemplate.psm1 and modify the following section:

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
$template = @"
###########################################################################
#
# NAME:
#
# AUTHOR: $env:USERNAME
#
# COMMENT:
#
# VERSION HISTORY:
# 1.0 $((get-date).ToShortDateString()) – Initial release
#
###########################################################################

"@

 

Note that the first new document automatically created when opening the PowerGUI Script Editor wont get pre-filled with the script template header, since the Script Template Add-on isnt loaded yet. However, all consecutive new documents will get the template automatically.

A similar Add-on is available here for PowerShell ISE, created by PowerShell MVP Ravikanth Chaganti.

If you`re interested in creating your own Add-ons for the PowerGUI Script Editor, have a look at this excellent tutorial created by Kirk Munro and Dmitry Sotnikov.