How to Comment Code in PowerShell ?

If you are new to PowerShell and wondering how to add comments with-in your Powershell code , here’s how you can do it.

How to Comment Code in PowerShell ?

Single Line Comment in PowerShell

# is one of the ways to add a single line comment in PowerShell. It was introduced in PowerShell v1.0.

Eg :

# This is a comment from DeveloperPublish

Multi-line Comment in PowerShell

You can use <# #> to add a multi-line comment in PowerShell. This was introduces in PowerShell 2.0 and is available in 2.0 and higher versions.

Eg :

<# Comment Line 1
    Comment Line 2
    Comment Line 3
#>

Share:

Leave A Reply

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

You May Also Like

Are you looking at importing DscResource with Relative Paths when working in PowerShell? If so, let’s have a look at...
If you want to find the version of the PowerShell that is installed on the PC , you can use...
There are many ways in which you can run your PowerShell Script. In this post , we will how to...