Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you comment out code in PowerShell?

How do you comment out code in PowerShell (1.0 or 2.0)?

like image 641
labyrinth Avatar asked Sep 08 '11 02:09

labyrinth


People also ask

How do you comment out multiple lines in PowerShell?

In PowerShell, use the # symbol at the beginning of a line to comment a single line. Multiline comments in PowerShell can be easily achieved by using <# at the beginning of the line and #> at the end of the code.

How do you comment a function in PowerShell?

Syntax for comment-based help in scriptsScript help can be preceded in the script only by comments and blank lines. If the first item in the script body (after the help) is a function declaration, there must be at least two blank lines between the end of the script help and the function declaration.

How do you comment out a script?

Creating Single Line Comments To create a single line comment in JavaScript, you place two slashes "//" in front of the code or text you wish to have the JavaScript interpreter ignore. When you place these two slashes, all text to the right of them will be ignored, until the next line.

What is the example of a block comment found in PowerShell?

A comment block in PowerShell starts with <# and ends with #> .


2 Answers

You use the hash mark like this:

# This is a comment in PowerShell 

Wikipedia has a good page for keeping track of how to do comments in several popular languages:

Comments

like image 30
adamleerich Avatar answered Sep 25 '22 02:09

adamleerich


In PowerShell V1 there's only # to make the text after it a comment.

# This is a comment in PowerShell 

In PowerShell V2 <# #> can be used for block comments and more specifically for help comments.

#REQUIRES -Version 2.0  <# .SYNOPSIS     A brief description of the function or script. This keyword can be used     only once in each topic. .DESCRIPTION     A detailed description of the function or script. This keyword can be     used only once in each topic. .NOTES     File Name      : xxxx.ps1     Author         : J.P. Blanc ([email protected])     Prerequisite   : PowerShell V2 over Vista and upper.     Copyright 2011 - Jean Paul Blanc/Silogix .LINK     Script posted over:     http://silogix.fr .EXAMPLE     Example 1 .EXAMPLE     Example 2 #> Function blabla {} 

For more explanation about .SYNOPSIS and .* see about_Comment_Based_Help.

Remark: These function comments are used by the Get-Help CmdLet and can be put before the keyword Function, or inside the {} before or after the code itself.

like image 93
JPBlanc Avatar answered Sep 23 '22 02:09

JPBlanc