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:
Random Comment Picker is a free online tool to easily generate a winner for a Facebook lottery, giveaway, contest or promotion. By entering the URL of your Facebook post, we can retrieve all comments and filter out duplicate names. You can pick a random winner out. Above comment repeated 18809 times. Echo microtime , '; // 0.251450508 They take up about the same amount of time (about meaning on a repeated testing, sometimes the difference between the control and the test was negative and sometimes positive).
<# comment
contines #>
contines #>
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.
See this template script, or read Help about_Comment_Based_Help for a full list of .Keywords.
Examples
Copy-Item demo.msi C:installdemo.msi #copy the installer
By using embedded comments you can document the arguments for a cmdlet:
Comment based help
Comment-based help topics can be added to functions and scripts. This is done using special help comment keywords that start with a period. Examples of these are below, you can add as many or as few of these to your script as needed to provide the relevant level of detailed help.
To display this help text, use Get-Help
e.g.
get-help ./script.ps1
get-help myfunction (this will only work once the function has been loaded/Dot sourced)
e.g.
get-help ./script.ps1
get-help myfunction (this will only work once the function has been loaded/Dot sourced)
Where to add the Comment-based help:
Comment-based help for a script must appear at the beginning of the script (it can also be placed at the end of the script file but only if the script is not signed.)
Comment-based help for a function can appear in one of three locations:
- At the beginning of the function body.
- At the end of the function body.
- Before the Function keyword. There cannot be more than one blank line between the last line of the function help and the Function keyword.
Most people put all comments at the beginning of the script/function.
Default Help
If you call get-help for a script that does not have any comment based help but does have parameters defined with a PARAM ( ) statement, then get-help will return those parameter details.
It is also possible to get a slightly more verbose set of default help text by including just <# .SYNOPSIS #> at the top of the script.
See Help about_Comment_Based_Help for more.
Copy and Paste
Because PowerShell supports Tab Completion you need to be careful about copying and pasting Space + TAB characters (particularly just before the # comment delimiter).
Example:
Function demo() {
} # comment
} # comment
^ That line is }<space><tab> #
when copied/pasted onto the PowerShell command line, this happens:
when copied/pasted onto the PowerShell command line, this happens:
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.
>> } .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 the 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'
Think about the place where you live, Wonder why you haven't before# - REM 'Stand'
Related PowerShell Cmdlets:
Escape characters - double to escape them
Copyright © 1999-2021 SS64.com
Some rights reserved
Some rights reserved
Comment Journal
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
contines #>
contines #>
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.
See this template script, or read Help about_Comment_Based_Help for a full list of .Keywords.
Examples
Copy-Item demo.msi C:installdemo.msi #copy the installer
By using embedded comments you can document the arguments for a cmdlet:
Comment based help
Comment-based help topics can be added to functions and scripts. This is done using special help comment keywords that start with a period. Examples of these are below, you can add as many or as few of these to your script as needed to provide the relevant level of detailed help.
To display this help text, use Get-Help
e.g.
get-help ./script.ps1
get-help myfunction (this will only work once the function has been loaded/Dot sourced)
e.g.
get-help ./script.ps1
get-help myfunction (this will only work once the function has been loaded/Dot sourced)
Where to add the Comment-based help:
Comment-based help for a script must appear at the beginning of the script (it can also be placed at the end of the script file but only if the script is not signed.)
Comment-based help for a function can appear in one of three locations:
- At the beginning of the function body.
- At the end of the function body.
- Before the Function keyword. There cannot be more than one blank line between the last line of the function help and the Function keyword.
Most people put all comments at the beginning of the script/function.
Default Help
If you call get-help for a script that does not have any comment based help but does have parameters defined with a PARAM ( ) statement, then get-help will return those parameter details.
It is also possible to get a slightly more verbose set of default help text by including just <# .SYNOPSIS #> at the top of the script.
See Help about_Comment_Based_Help for more.
Copy and Paste
Because PowerShell supports Tab Completion you need to be careful about copying and pasting Space + TAB characters (particularly just before the # comment delimiter).
Example:
Function demo() {
} # comment
} # comment
Youtube Comments
^ That line is }<space><tab> #
when copied/pasted onto the PowerShell command line, this happens:
when copied/pasted onto the PowerShell command line, this happens:
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.
>> } .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 the 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'
Think about the place where you live, Wonder why you haven't before# - REM 'Stand'
Commentator
Related PowerShell Cmdlets:
Commentsold
Escape characters - double to escape them
Justin Thomas Comment
Copyright © 1999-2021 SS64.com
Some rights reserved
Some rights reserved