PowerShell for Windows Admins

Sep 29 2017   4:00PM GMT

PowerShell comments

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:
Powershell

Putting comments into your code has been a long established practice – this is how you do PowerShell comments

A single line comment is indicated by the # symbol

# This is a comment
Get-Process

You can put a comment at the end of a line but not in the middle. Once you’ve added a comment that’s it for the rest of the line

Get-Process # This is a comment

In ISE and Visual Studio Code comments are shown in green by default

You can also create multi-line comments

<#
This is
a multi-line
comment
#>
Get-Process

Be careful if you use # symbols in file names or other data in PowerShell – you may end up with PowerShell thinking you’ve declared a comment

1  Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • spacenomyous
    You can use the multi-line comment for inline comments. I use this while troubleshooting. In this example I'm testing out different filters.

    Get-ADUser -Filter * <#{Enabled -eq True}#> -Properties *


    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: