PowerShell - Comment

By xngo on March 11, 2020

Writing comments are important in your PowerShell script. They help the next maintainers understand your scripts. Or, they will help you understand your own code down the line, say in 6 months from now.

In PowerShell, you can comment in 2 ways:

  • Single line comment: Comment starts with pound key(#).
  • Multiple lines comment: For multiple line comment, put <# at the beginning and #> at the end.

Here are the examples:

# This is an important variable.
$counter = 7
$sum = 88   # The $sum starts from 88.
<# This function will 
    do magic stuff.
Function doMagic()
    # Do some magic....

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.