Home > DevOps > Add PowerShell user snippet in Visual Studio Code to add comment based help header
Visual Studio Code

Add PowerShell user snippet in Visual Studio Code to add comment based help header

I was tired of typing out comment blocks in each of my PowerShell scripts so I decided to create a snippet in Visual Studio Code. All i have to do now is create a file with a ps1 extension and start typing inshead until intellesense pop’s up and then hit enter. All good to go!!

 This is inside of my powershell.json file.

	"Insert Doc Header":{
		"prefix": "inshead",
		"body": [
			"<#",
					"\t.SYNOPSIS\n\n",
					"\t.DESCRIPTION\n\n",
					"\t.PARAMETER\n\n",
					"\t.EXAMPLE\n\n",
					"\t.INPUTS\n\n",
					"\t.OUTPUTS\n\n",
					"\t.LINK\n\n",
					"\t.NOTES\n\n",
			"#>"
		],
		"description": "Adds comment based help header."
	}

Intellisense looks like

Then it the finished product looks like:

Microsoft has additional documentation for creating user snippets in Visual Studio Code here: https://code.visualstudio.com/docs/editor/userdefinedsnippets

I have to thank this page for getting me started https://jdhitsolutions.com/blog/scripting/5488/adding-powershell-snippets-to-visual-studio-code/