Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

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:

Syntax1:

Syntax2:

Examples

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.

Output:

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






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA