Code Snippets are a great tool in any code editor. Snippets are templates which make it very easy to implement commonly used code such as loops. I find that code snippets really shine for less-commonly used code as well. While you may not need some particular code often, it can break your flow if you end up having to stop and search docs to remind yourself how to implement it. For me, a great example of this is Write-Progress.
I occasionally need to bulk-analyze logs with scripts, which sometimes leads to long running processes. In these cases, Write-Progress is great way to monitor status and make sure your script is moving along. Unfortunately, I use it infrequently enough that I always have to find a code example from previous work so that it’s implemented the way I like.

This seems like a good opportunity for a code snippet. VSCode already has several foreach snippets, but only for basic use cases. So, I decided to create a custom user snippet which sets up a foreach loop with Write-Progress already set up.
Start by creating a new global user snippets file. In VSCode, go to File > Preferences and select ‘Configure User Snippet’. Next, in the palette select ‘New Global Snippets file..’.

A new file will be created in your AppData folder which is located here "$env:APPDATA\Code\User\snippets\". Insert the new snippet definition, save, and close.
"Foreach with Progress": {
"scope": "powershell",
"prefix": "foreach-progress",
"body": [
"\\$total = $${1:array}.count",
"\\$i = 1",
"Foreach ($${2:item} in $${1:array}) {",
" \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)",
" Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent",
" # Insert Code Here",
" ${0}",
" ",
" \\$i++",
"}",
""
],
"description": "Insert a foreach loop with Write-Progress initialized"
}
You can download the code snippets file here: Code Snippets
Now, you have a working code snippet which will create a Foreach loop with Write-Progress already set up! Simply use tab to move through and customize the placeholders. Not only does this make it much quicker to implement uncommon code with less distractions, but it helps standardize all future implementations as well.

The full guide for Snippets can be found in the VSCode docs here: Snippets in Visual Studio Code.
I hope you found this useful.
Remember, a script a day keeps the work away!
~ian-mor