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!"


Above 3 lines of code is commented out!

PowerShell Comment out line and block of code examples

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap