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:

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!