Adding Custom Snippets to ISE editor

by May 1, 2013

The new PowerShell 3.0 ISE editor features a snippet menu that lets you easily insert predefined code snippets. Simply press CTRL+J to open the menu, select the snippet, and insert it into your code.

To add more snippets, here is the way to go:

$myCodeSnippet=@'
function Verb-Noun
{
  param()

}  
'@

New-IseSnippet -Title 'Function body (simple)' -Description "My simple Function snippet" 
-Author $env:username -Text $myCodeSnippet Force

This adds a new snippet called "Function body (simple)" to your snippet menu. It is stored permanently, so next time you launch the ISE editor, it is still there. Use CTRL+J to open the snippet menu, and you will find your new custom snippet. From now on, whenever you need to insert the same types of code blocks, just define a code snippet.

Twitter This Tip! ReTweet this Tip!