# 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.

Examples

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

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).

Example:

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'

Related:

Escape characters - double \\ to escape them


© Copyright SS64.com 1999-2013
Some rights reserved