The Snippet Editor
For those of you who are not familiar with snippets, they are small pieces of reusable code that can be quickly inserted into your script while editing.
This piece or snippet of code can come in a various forms, such as a full-fledged function or a simple single line statement. Snippets can also come in
various languages such VBScript, PowerShell, C#, etc. The Snippet Editor makes it fast and easy to create your own custom snippets and edit existing
snippets. PowerShell Studio comes with an extensive library of reusable code snippets. It lets you save any text or code block as a snippet to automate
code development and prevent errors.
The Snippet Editor will launch when you edit an existing snippet or create a new snippet in PowerShell Studio. It is a self-contained program, and it
supports multiple programming languages. Snippets are reusable blocks of code that you can add to your PowerShell scripts, thus saving you time and
reducing errors. Snippets can include placeholders, and PowerShell Studio will prompt you to supply values for these when the snippet is used. Snippets are
stored in the following folder:
%ProgramData%\SAPIEN\PowerShell Studio 2015\Snippets

The main section of the snippet editor allows you to enter the following information:
-
Title
The name of the snippet.
-
Shortcut
The text you need to type in the code editor to invoke the snippet.
-
Description
A short description of the snippet to remind you what it does.
-
Author
Your details.
-
Help URL
A link to help information. This will be displayed in the code editor.
-
Language
This should always be set to PowerShell if you intend to use your snippet in PowerShell Studio.
-
Type
This setting defines the intended use of the snippet. It also defines where PowerShell studio will display the snippet.
PowerShell Studio provides two context menu options for inserting snippets in the code editor.
-
Insert Snippet…
Only display snippets marked as Expansion or
Both.
-
Surround With Snippet…
Only displays snippets marked as Surrounds with or Both
If your snippet is intended to be simply inserted into a code file, set this option to Expansion.
If your snippet can surround existing code, set this option to Surrounds with.
If your snippet can be used in both ways, set this option to Both.
NOTE:
If you choose Surrounds with or Both, you must include the placeholder $selected$ somewhere in you snippet code body, otherwise you may overwrite user code when your snippet is used.

-
References
This section helps PowerShell Studio to understand any dependencies that your snippet has. The assemblies you list here will be loaded into PowerShell
Studio when you use the snippet.
-
Imports
This section is not used for PowerShell snippets
-
Variable Details
This section is used to configure placeholder variables used in a snippet. Placeholder variables are added to a snippet when you-right click on the
snippet code editor and choose Add Variable.

Once you have given the variable name it will appear in the snippet as $<variable name>$ (e.g. $computerName$) and you can configure the variable
properties.
-
ID
The variable's name.
-
Default
A default value if required.
-
Function
Not used in PowerShell snippets.
-
Type
Not used in PowerShell snippets.
-
Kind
Not used in PowerShell snippets.
-
Editable
Not used in PowerShell snippets.
-
ToolTip
Provides some text explaining the purpose of the variable. This helps the snippet user understand how to complete the snippet. PowerShell Studio will
display these tooltips as the user navigates between the placeholders in the PowerShell Studio code editor.
Two built in variables are provided:
-
$selected$
Allows you to merge code from the code editor into your snippet when it is used. For example you could create a snippet called ExtractFunction
containing this code:
Now a user can highlight lines of code and use this snippet to refactor them into a reusable function.
-
$end$
Specifies where the cursor should be placed when a snippet is inserted into the code editor.