PowerShell Multiline/Block Comment Tutorial

PowerShell provides the multiline comment or block comment in order to create comments which wraps multiple lines. Even PowerShell provides single line comment too but it is not useable to create long description. PowerShell multiline or block comments can be used to explain the complete PowerShell module, specific function, part of the PowerShell script and code.

Multiline or Block Comment

The <# characters are used to set the start of the multiline/block comment and #> characters are used to set the end of the multiline/block comment. All characters between <# and #> are interpreted as comments. Even these contains PowerShell commands they are not interpreted as PowerShell statement or command. The <# and #> are provided with the PowerShell version 2.

<# 
   This is a multiline comment
   This is a block comment
   Get-Date command not executed as this is a comment
#>

Get-LocalUser
Multiline or Block Comment

Multiline or Block Comment

The <# and #> multiline comment structure is represented with the PowerShell version 2. In Powershell version 1 the single line comment was created with the hash (#) sign. Multiple hash signs can be used to create multiline/block comments.

# This is a multiline comment
# This is a block comment
# Get-Date command not executed as this is a comment


Get-LocalUser
Multiline or Block Comment
See also  How To Show/Display File Extensions In Windows?

Leave a Comment