# comment

In PowerShell single line comments start with a hash symbol, everything to the right of the # will be ignored.

# comment

In PowerShell 2.0 and above multi-line block comments can be used:

<# comment #>

Multi-line comments are typically used to add descriptive help at the start of a script, but also work to embed comment text within a command.

Comment-based Help was also added in PS 2.0, this allows the addition of some standardised tags to a scripts comments which allow the Script to interact with Get-Help.
See this template script, or read Help about_Comment_Based_Help for a full list of .Keywords.


Copy-Item demo.msi C:\install\demo.msi #copy the installer

   Running this script will make your computer catch fire!
   Last updated: 1666-09-02

Get-Content -Path <#configuration file#> C:\app64.ini

By using embedded comments you can document the arguments for a cmdlet:

PS C:\> Get-ChildItem    <# list the items               #> `
    -Path   $env:windir  <# of the Windows system folder #> `
    -Filter *.dll        <# that are DLLs                #> `
    -Recurse             <# and search all subfolders    #>

Copy and Paste

Because PowerShell supports Tab Completion you need to be careful about copying and pasting Space + TAB characters (which most often sneak in before comments).


Function demo() {
} # comment

^ That line is }<space><tab> #
when copied/pasted onto the PowerShell command line:

PS C:\batch> Function demo() {
>> } .\aaardvaark.cmd# comment
The term '.\aaardvaark.cmd#' is not recognized as the name of a cmdlet, function, script file...

What is happening is that the space-tab gets expanded to match the first file in the current directory, in this case aaardvaark.cmd. If the sequence had been <space><tab><space> and the first file had been a PowerShell script or an executable then it would actually be run.

If your white space consists of nothing but <space> characters (or nothing but <tab> characters) then this will never occur.

#Now stand in the place where you work, Now face West
Think about the place where you live, Wonder why you haven't before# - REM 'Stand'


Escape characters - double \\ to escape them

Copyright © SS64.com 1999-2017
Some rights reserved