PowerShell VSCode snippets
Continuation of the first VSCode settings post if you will 😊
Given that I have worked with many engineers over the years, I have noticed that very few of them are aware of the snippet feature in VSCode. Even fewer actually use them.
So maybe this will help somebody out there 😊
VSCode PowerShell snippets
So what are PowerShell snippets and why should you care?
Snippets are pre-defined code templates that you can insert into your code to save time and reduce errors. They are a great way to speed up your workflow and improve your code quality.
My favourite snippet is the calculated-property snippet, which creates a PowerShell calculated property with the proper syntax.
How often do you want to get what I would call a custom property that you want to select and in line do something with. Like this:
| |
I for one, never remember the syntax for that, so this snippet saves me a lot of time 😊
The easiest example is Get-Disk with some calculated properties:
| |
Example output
| |
How to insert a snippet
To insert a snippet, press Ctrl + Alt + J to bring up the menu, type the snippet name and press Enter.

Where are the VSCode PowerShell snippets located?
powershell.json file there, so you will need to create it. | |
If you want to use the $env:APPDATA variable:
| |
Sample snippet file
| |
This creates a snippet that can be used in PowerShell files with the prefix credential, pscredential, credentialobject, or newcredential. It looks like this:
| |
Super handy if you ask me 🤣
JSON escape characters tips for the snippet file
JSON escape characters:
- For a tab:
\t - To escape literal
$(dollar sign) prefix the dollar sign with:\\ - To escape double quotes prefix with:
\ - For a blank space use:
""
Bonus tip
The best thing about those snippets is that if you synchronise your VSCode settings using Settings Sync, those snippets will be synchronised too! But maybe that is a blog post for another day 😄