您可以在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