EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell MultiLine Comment
 

PowerShell MultiLine Comment

PowerShell-MultiLine-Comment

Introduction to PowerShell MultiLine Comment

PowerShell Multiple lines comment is the way of adding the description of the script, function or writing the help to describe the functionality to get a better understanding and the explanation of the script or the part of the script without executing that part and besides, it is helpful to write the comment-based help about the function by adding the syntax, parameters, examples, etc.

 

 

Syntax:

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Multiline comments are described inside the block <#…#>

Comment-based help.

<#
.<help keyword>
<help content>
#>

How does multiline comment work in  PowerShell?

To add the single-line comment, we use the # in front of the line, and in PowerShell 2.0 or earlier version this was the only way to add the multiple-line comments. This means if you have the description of the 10 lines then you need to put 10 times ‘#’ in front of the line.

Single line comments ‘#’ are still there for describing the small portion of the function or the script. See how the below single-line comments look like.

# This part won't be executed

Output:

PowerShell MultiLine Comment 1

Even the expressions or any syntax won’t execute inside this block.

# Get-Date

Output:

get date

Whenever PowerShell finds the keywords # or any content between <#…#> keywords, it skips that part for the execution.

Now let say we have a script and need to describe something about it. If we are using the single-line comments, can you assume how it seems ridiculous to write every time # infornt of the line?

PowerShell MultiLine Comment 2

This is how we need to put the # sign against each line by adding simply the multiline comments <#…#> in the script, we can avoid # sign every time.

PowerShell MultiLine Comment 3

Few things to Note:

  • You can’t format the fonts the comments entered inside the block. Try making fonts Bold, change the color of the font, it won’t work because it is the unique format for each editor. The color display of the comment block depends on the editor we are using and the theme you selected.

Multiline or single-line comments might look differently in PowerShell ISE and Visual Studio code. Below are the multiline comments from the PowerShell ISE and VS code.

<# This comment is from the PowerShell ISE

Font color is different than VS code

#>

From VS code with the Atom theme.

<# This comment is from the VS code
Font color is different than PowerShell ISE
#>

  • You can’t pass any variable value inside the multiline comments block. For example,

$name = "PowerShell"
<#
This $name variable won't expand because
This is a multiline comment
#&gt
;

Output can’t expand the name.

PowerShell MultiLine Comment 4

Examples

Let us discuss examples of PowerShell MultiLine Comment.

Example #1: Adding a multiline comment to describe the script

When you write a script, you can describe the script information like version, functionality with the multiline comments as shown below and you can use it any number of times because there is no limit to it.

Here is a combination of the single and multiline comments.

<#
Script Version: 1.0
Script Author: Chirag Nagrekar
Repo Location: Company Git Location
#>
function StopServices{
<#
Using foreach loop for the script
Getting the name of the servers to stop the Spooler service
#>
foreach($server in $servers){
Stop-Service -Name Spooler -Force -Verbose
}
}
#Calling StopServices Function
StopServices

Example #2: Shortcut to add multiline comments

In the visual studio code, there is a shortcut to add the multiline comments by selecting the lines that we need to comment and then pressing the ALT + SHIFT + A button.

For example,

This is the first line
This is the second line
This is the third line

We need to comment on the above lines. First, select those lines and press ALT + SHIFT + A.

Output:

powershell output

Example #3: Adding multiline comments for the help description

Multiline comments are also helpful for writing comments-based help as shown below. They are specific and described with the.HelpName.

function CheckConnectivity{
param(
[String]$computername,
[String]$Timeout
)
<#
.SYNOPSIS
This function retries the computer connectivity for the specific time.
.PARAMETER ComputerName
Remote Computer Name
.PARAMETER Timeout
Specify the timeout in seconds
.EXAMPLE
PS> CheckConnectitivy -ComputerName TestComp -Timeout 120
#>
}

When you check the help related to this function, the above comment-based help useful for describing the function.

output

output 1

To know more about this section, use the below link.

microsoft.powershell.core

Conclusion

Not only PowerShell but almost all other high-level programming languages also use single and multiline comments so that when we write a script, we don’t need to print everything on the output console but we need users or scripters to understand what the particular script is for, you can mention script version. Moreover, you can add script-related help.

Recommended Articles

This is a guide to PowerShell MultiLine Comment. Here we discuss definition, syntax, and parameters, How does multiline comment works in  PowerShell? examples with code implementation. You may also have a look at the following articles to learn more –

  1. PowerShell unzip
  2. PowerShell join string
  3. PowerShell Exit
  4. PowerShell Wait

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW