您可以在PowerShell帮助系统可以解码的文件顶部添加一定的注释风格。这里有一个例子:
<#
.SYNOPSIS
.
.DESCRIPTION
.
.PARAMETER Path
The path to the .
.PARAMETER LiteralPath
Specifies a path to one or more locations. Unlike Path, the value of
LiteralPath is used exactly as it is typed. No characters are interpreted
as wildcards. If the path includes escape characters, enclose it in single
quotation marks. Single quotation marks tell Windows PowerShell not to
interpret any characters as escape sequences.
.EXAMPLE
C:\PS>
<Description of example>
.NOTES
Author: Keith Hill
Date: June 28, 2010
#>
function AdvFuncToProcessPaths
{
[CmdletBinding(DefaultParameterSetName="Path")]
param(
[Parameter(Mandatory=$true, Position=0, ParameterSetName="Path",
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Path to ...")]
[ValidateNotNullOrEmpty()]
[string[]]
$Path,
[Alias("PSPath")]
[Parameter(Mandatory=$true, Position=0, ParameterSetName="LiteralPath",
ValueFromPipelineByPropertyName=$true,
HelpMessage="Path to ...")]
[ValidateNotNullOrEmpty()]
[string[]]
$LiteralPath
)
...
欲了解更多信息,请参阅帮助主题 - man about_comment_based_help
。
我明白了。所以'Parameter'属性上的'HelpMessage'属性实际上被* PowerShell帮助系统忽略*。这并不令人困惑。 :/ – 2011-03-08 20:39:34
是的,它有点混乱。不过,参数表上的HelpMessage属性不会被忽略。它用于调用该命令时未指定强制参数。此时会提示您输入该参数的值。如果指定了“HelpMessage”,则该文本将显示为该提示的一部分。 – 2011-03-08 22:22:24
但只有当你输入“!?”时当PowerShell提示输入该必需参数的值时。这是鲜为人知的。 – JasonMArcher 2011-03-09 20:06:19