A curated list of awesome vscode snippets for PowerShell.
Inspired by the awesome lists, focusing on PowerShell snippets in VSCode
Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements. Check out the VSCode documentation on snippets. It provides an overview and instructions on how to author snippets. It's really simple - just a little bit of JSON.
To contribute, check out our guide here.
Table of Contents |
---|
PSCustomObject: A simple PSCustomObject by @brettmillerb |
DateTimeWriteVerbose: Write-Verbose with the time and date pre-pended to your message by @ThmsRynr |
A simple PSCustomObject by @brettmillerb. It has 4 properties that you can tab through to quickly fill in.
"PSCustomObject": {
"prefix": "PSCustomObject",
"body": [
"[PSCustomObject]@{\r",
"\t${item1} = ${Property1}\r",
"\t${item2} = ${Property2}\r",
"\t${item3} = ${Property3}\r",
"\t${item4} = ${Property4}\r",
"}"
],
"description": "Creates a PSCustomObject"
}
Quickly add a Write-Verbose
with the current date and time inserted before the message you're going to write to the verbose stream, by @ThmsRynr.
"DateTimeWriteVerbose": {
"prefix": "dtwv",
"body": [
"Write-Verbose \"[$(Get-Date -format G)] ${1:message}\"$0"
],
"description": "Pre-pend datetime for Write-Verbose"
}
If you'd like to add a snippet to this list, open a pull request with the following changes:
You need to add an item to the table of contents. The addition should follow the alpha ordering of the list. The ToC item template looks like this:
| [Name of snippet](link to header of your snippet): _some short description_ |
An example looks like this (NOTE: all lowercase link):
| [PSCustomObject](#pscustomobject): _A simple PSCustomObject_ |
which will show up in the ToC like this:
Table of Contents |
---|
PSCustomObject: A simple PSCustomObject |
You need to also add an item to the body in alpha order. The body item template looks like this:
### Name of snippet
Enter your description here. It can be the same as the ToC or a longer version.
#### Snippet
```json
{
"Put your":"snippet here",
"indent it":"properly"
}
```
An example looks like this:
### PSCustomObject
A simple PSCustomObject.
#### Snippet
```json
"PSCustomObject": {
"prefix": "PSCustomObject",
"body": [
"[PSCustomObject]@{",
"\t${1:Name} = ${2:Value}",
"}"
],
"description": "Creates a PSCustomObject"
}
```
which will show up in the body like this:
A simple PSCustomObject. Note, this snippet ships with the PowerShell extension.
"PSCustomObject": {
"prefix": "PSCustomObject",
"body": [
"[PSCustomObject]@{",
"\t${1:Name} = ${2:Value}",
"}"
],
"description": "Creates a PSCustomObject"
}