Home Office Tools PowerShell Comments

PowerShell Comments

by Easy Excel Tutorials

PowerShell Comments

When you want to help others by providing the information about a code, then you must use the comments in that code.

Just like other programming or scripting languages, you can give the comments in a PowerShell for the documentation purpose.

In PowerShell, there are two types of comments:

  • Single-line Comment
  • Multiple-line comment or comment block

Single line comment

Single line comments are those comments in which you can type a hash symbol # at the beginning of each line. Everything to the right of the hash symbol will be ignored. If you write the multiple lines in a script, you had to use the hash # symbol at the starting of each line.

Syntax of Single line comment

The following are the two syntaxes for the single-line comment:




Example1: This example displays how to use the comment at the end of a line

Example2: This example displays how to use the comment before the code and at the end of any statement.


2  4  6  8  10  

Multiple line comment

With PowerShell 2.0 or above, multiple line comments or block comments have been introduced. To comment the multiple lines, put the <# symbol at the beginning of the first line and #> symbol at the end of the last line.

Syntax of multiple line comment

The following block displays the syntax of multiple line comment:

Example: The following example describes how to use the multiple line comment in code.

Type the following command to display the output of above example:

PS C:> $fact  120  

You may also like