0

How can we add multiline comment in powershell script?

$a=10 $b=20

writ-host "Sum"

Preeti
  • 421
  • 5
  • 14

3 Answers3

0

We can add multiline comment in powershell as below

<#

$a=10

$b=20

writ-host "Sum"

#>

Preeti
  • 421
  • 5
  • 14
0

Yes, PowerShell supports multi-line block comments:

<#
$a=10
$b=20

Write-Host "Sum"
#>

Do note that block comments are non-nestable:

<# 
This is part of the comment
<#
$a=10
$b=20

Write-Host "Sum"
#>
But this is not...
#>
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
0

You can use the <# and #> symbols to create a comment block.

<#
    $a=10
    $b=20

    writ-host "Sum"
#>

Documentation: https://learn.microsoft.com/en-us/powershell/scripting/developer/help/syntax-of-comment-based-help?view=powershell-7.1

Coconut
  • 2,024
  • 18
  • 25