How do you comment out code in PowerShell (1.0 or 2.0)?
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.
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.
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.
A comment block in PowerShell starts with <# and ends with #> .
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With