I am new to PowerShell and would like to know How to comment PowerShell code? I am currently using PowerShell 7 on Windows 11.
Thanks
You can use # to comment single line PowerShell Code and <# and #> symbols to create a multiple-line comment block in Powershell.
# Your Comment Here in PowerShell
Example:
Get-Process -Name *host*
In Powershell 2.0 or above, you can make multi-line comment as below
<#
This is Comment
This is also comment, line 2
Some More text here
#>
Example:
if (Get-Service $servicename -ErrorAction SilentlyContinue)
{
Write-Host "$servicename exists"
<#
Multi-line Comment
Here it would not execute
#>
}
Also in PowerShell ISE you can hit Ctrl+J
to open the Start Snipping menu and select Comment block to add it.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly