Powershell Comments



Comments will not be executed by Powershell.
Comments can be added to explain the Powershell, or to make the code more readable.
Single line comments start with #.
The following example uses single line comments to explain the code:
Like other languages powershell also supports single line and multi line comments.
Initially in PowerShell V1 there's only # to make the text after it a comment. Starting PowerShell V2 Microsoft come up with block comments (multi-line)

Example


<# #>

Copy and Try it

can be used more specifically for SYNOPSIS, DEsCRIPTION, NOTES, LINK help comments.

Script example:

$greeting = "Hello" # This line is single line comment.
# This line is second line comment.
$name = read-host "What is your name?" # This comment line is new.
"$greeting, $name!"

Begin the comment with the <# tag, and end the comment with the #> tag:

<# this is a comment 
   on several
   different
   lines
   #>

Copy and Try it