This is my first User Snippet posted for Visual Studio Code.
I know there is a default snippet included with the PowerShell extension.

However, I want to add additional information and have it inserted automatically.

To access the default Comment-Based help snippet, simply type comm in Visual Studio Code, and IntelliSense will display the comment-help snippet, as shown in the image below.

This option is better than not using Comment-Based Help for your script or function.

It’s great! Everything required for Comment-Based Help is included.

HOWEVER…

<#
.SYNOPSIS
    A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
    A longer description of the function, its purpose, common use cases, etc.
.NOTES
    Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
    Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
    Test-MyTestFunction -Verbose
    Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>

I always include name, author, version, and date in the Notes section, and the script name in the Example section.

But I don’t want to type this information manually every time.
I’m a bit lazy!

Here is my standard Comment Based Help:

<#
    .SYNOPSIS
        A short description
    .DESCRIPTION
        A longer description  
    .PARAMETER Name
        Specifies the name of the parameter
    .EXAMPLE
        Get-Information.ps1 -Parameter "ParameterValue"
    .NOTES
        NAME:       Get-Information
        AUTHOR:     Fredrik Wall
        VERSION:    1.0
        CREATED:    2025-06-04
#>

I have also created a PowerShell user snippet for this.

There are many variables available for Snippets in Visual Studio Code, and I use several of them.

Example – To get the PowerShell script name, I use $TM_FILENAME.

Name – For the script name without the .ps1 extension, I use $TM_FILENAME_BASE.

Author – This one was a bit tricky to automate. I use ${WORKSPACE_NAME}.

Created – I use ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE} here. You can adjust this format to match your country’s date style.

All available variables can be found on the User Defined Snippets page:
https://code.visualstudio.com/docs/editing/userdefinedsnippets

To be able to get the automatically Comment Based Help with all information as above you first of all need to add this to the PowerShell User Snippet JSON file.

"Comment Based Help": {
		"prefix": "Comment Based Help",
		"body": [
		  "<#",
		  "    .SYNOPSIS",
		  "        A short description",
		  "    .DESCRIPTION",
		  "        A longer description  ",
		  "    .PARAMETER Name",
          "        Specifies the name of the parameter",
		  "    .EXAMPLE",
		  "        $TM_FILENAME -Parameter \"ParameterValue\"",
		  "    .NOTES",
		  "        NAME:       $TM_FILENAME_BASE",
		  "        AUTHOR:     ${WORKSPACE_NAME}",
		  "        VERSION:    1.0",
		  "        CREATED:    ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}",
		  "#>"
		],
		"description": "Comment Based Help By PowerAdmin.se"
	  }

The easiest way to open the JSON file is by using Shift+Ctrl+P (Command Palette) and searching for Snippets: Configure Snippets. Then select powershell.json (PowerShell).

Next, insert the code above between the { and }.

If you already have other snippets, add a , after the last one before pasting the new code. Save the file afterward.

Now, you will have a snippet that inserts this information automatically…
…as long as you save your script first with your chosen name.

In my example: Get-Information.ps1

Finally, go to File and select Save Workspace As with your name to set your name as the Author.

This was a brief guide, but it provides helpful insights that assist me every single day without fail.


Leave a Reply

Your email address will not be published. Required fields are marked *

The PowerAdmin
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.