Want to add your PowerShell code snippets to PowerGUI Script Editor?
It is actually as easy as adding your xml .snippet file to the C:\Program Files\PowerGUI\snippets
folder.
You can create a new file manually or use any Visual Studio-compatible snippet editor. I am using Snipp Dogg which is a free open source project on codeplex. So my instructions below are using this tool but anything else would do.
1. Run the tool as Administrator (or it would not be able to save to Program Files if you are on Vista or later.)
2. You can see and study any of the snippet files shipped with PowerGUI:
3. Click the New button to create a new snippet and then paste your code into the central pane – in my example I start with advanced function code from PowerShell v2 example:
4. If you want your snippet to have placeholders for certain variable names, parameters, and so on, you need to replace each of them with $some_kind_of_id$. In addition to that you can put $selected$ in front of the one you want to become selected once the snippet is inserted.
In my example, I am making the function name and the variable name these snippet parameters (in snippet lingo “literals”) and make the function name selected by default:
5. Fill out other snippet parameters in the right-hand pane (Snipp Dogg does not have powershell as a language option – shame on them – so either change it in the xml file later on or just leave it as csharp – PowerGUI does not check this field):
6. Expand the Literals collection and click New to add a new literal (remember: we need to specify two):
7. Fill out and save (by clicking OK) both functionname and param:
8. Save the snippet to the C:\Program Files\PowerGUI\snippets
folder (requires admin rights in Vista and later):
9. Start PowerGUI Script Editor and insert the snippet:
That’s it! Happy scripting! 😉
Tags: IDE, KB, PowerGUI, PowerShell