Of course, this how to comment out code in PowerShell script is specifically written for multiple comment options in PowerShell.
Comment Out Code in PowerShell Script
Equally important, we comment out code in PowerShell script for the references only. Consequently, we can add single line comment, multi-line comment in PowerShell script.
Single Line Comment in PowerShell Script
Indeed, You can add symbol (#
) for single line comment in PowerShell script. In fact, single line code helps the reader and writer to quickly reference the code after the line.
# You can Find the Process ID (PID) using this Command in PowerShell Get-Process
Further, you can also add symbol (#
) for single line comment in PowerShell script anywhere in the line. However, adding symbol (#) in the beginning of line will convert the all the line into comment. Furthermore, you can add symbol (#
) after the code and it will work perfectly.
Get-Process # You can Find the Process ID (PID) using this Command in PowerShell
Multi-line Comments in PowerShell Script
Certainly, You can add multi-line comments in PowerShell script. For example, you can use the <#
and #>
symbols to create a comment block. Most importantly, you must use the <# and #> when you start multi-line comment in PowerShell script. Otherwise, your PowerShell script will through syntax error.
<# .DESCRIPTION You can Find the Process ID (PID) using this Command. We used this command in our blog post. #> Get-Process
Subsequently, I used .DESCRIPTION
in the above code example. This is called comment-based help keyword and you can read more about in reference link.
PowerShell ISE Comment Block
Above all, PowerShell ISE comment block is an added beauty to you PowerShell ISE. You can use Ctrl+J to open small Start Snipping menu to add comment block in PowerShell ISE.
PowerShell Comments
In fact, you can add PowerShell comments as much as we need to elaborate our code. Thus, You can follow always comment the code liberally practice.
- Firstly, in PowerShell V1, you can only add symbol (
#
) for writing comments. - Secondly, since PowerShell V2, you can use the
<#
and#>
symbols for multi-line comments in PowerShell script.