Current project for the PowerShell VSCode project is opening the Snippets up to the community and for the community. The was announced in the VSCode channel in the Slack group, a resource I strongly recommend.
I have taken the great base snippet file Keith Hill provided in the early days of using VSCode as my PowerShell editor and converted my ISE snippets from the XML file. I can’t complain as I had a useful collection of code snippets for ISE but looking at the format and capabilities that VSCode provided, I quickly started adding my snippets to the base collection Keith Hill provided.
I have one that I like to include in my End statement of a script. As it stood it was usable but was lacking. Watching the community post snippets I saw a chance to take this little nugget and make it better. The code simply starts a remove-variable so I can clean up variables before the script finishes and then initiate a garbage collection via .Net. Below is what the snippet looked like when I used in my code:
I call the snippet and the code is added, including the tabs and carriage returns. The text area after the Name parameter is where the cursor goes because of ${1:variablestoberemoved} but that is far as the Snippet automation would go. So I created an empty JSON file and started with the snippet as I had entered it. Then I progressed with fixing and adding some pieces to the snippet. I would then take the new version of just that snippet and replaced the one in the PowerShell.json file, then in a blank script file I would use the prefix and check the progress.
