How to Comment out Code in PowerShell Script

If you have a PowerShell Script and you want to comment out a certain code line or a block, then you can achieve it using,


Comment Syntax Description
# To comment single line of code.
<# multiple lines of code #> To comment out a block of code.

Let's take a look at both of them using examples.

Example 1: Comment single line of code

# no = 20
$number = 30
Write-Host "The number is: $number"

Example 2: Comment Block of code

<# $no1 = 10
$no2 = 20
$no3 = 30
Write-Host "The number is: $no1" #>

Write-Host "Above 3 lines of code is commented out!"

Output:

Above 3 lines of code is commented out!

PowerShell Comment out line and block of code examples

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!