Commenting multiple lines in Power Shell

In one of my recent blogs I talked about how to comment code in PowerShell. That was by using a Hash Tag or a Pound Sign. But what if you would like to comment out multiple lines of code? It would be Inconvenient to Add a Hash Tag against each line of code that you want to comment out. That task is cumbersome and time consuming. Fortunately many programming languages and scripting tools have a way of commenting out multiple lines of code.

In Power Shell, one could comment out multiple lines of code by just following these steps-

You can start the comment block by adding this <#  to the code. And it can be ended by  this #> For Example, this would be the way to comment out a block of code.

 

$a=5

Write-Host "Initialized a variable"

<# $b=2

Write-Host "Initialized a second variable" #>

This example comments out code starting from the place where the variable b was Initialized.

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s