我正在尝试设置我的PowerShell命令,因此Get-Help -full
将显示有关如何运行脚本的完整信息。我有要在此帮助中显示的默认值。我有以下几点:
<#
.PARAMETER SenderEmail
The name of the user who is sending the email message. Although not
officially required, it will be checked to make sure it's not blank.
#>
Param (
[String]
[Parameter(
Position=1,
HelpMessage="Sender's Email Address")]
$SenderEmail = "bob@fubar.com"
)
然而,当我键入 Get-Help -detail 时,会出现以下内容。
-SenderEmail <String>
The name of the user who is sending the email message. Although not
officially required, it will be checked to make sure it's not blank.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters?
如何获得显示此参数默认值的帮助?
我认为您无法在 V2 的高级函数中显示默认值。我甚至尝试过[System.ComponentModel.DefaultValueAttribute(")],但没有运气。但是,如果有任何安慰,这似乎在 V3 中按原样工作。
V3 ONLY!!
PS> Get-Help .help.ps1 -full
NAME
C:temphelp.ps1
SYNOPSIS
SYNTAX
C:temphelp.ps1 [[-SenderEmail] <String>] [<CommonParameters>]
DESCRIPTION
PARAMETERS
-SenderEmail <String>
The name of the user who is sending the email message. Although not
officially required, it will be checked to make sure it's not blank.
Required? false
Position? 2
Default value bob@fubar.com
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
RELATED LINKS
似乎没有办法指定参数的默认值。您需要在参数的说明中指定它。
<#
.PARAMETER SenderEmail
The name of the user who is sending the email message. If not
specified, a default value of bob@fubar.com will be used
#>
这篇文章在故障排除部分有信息 http://technet.microsoft.com/en-us/library/dd819489.aspx。
Default values and a value for "Accept Wildcard characters" do not appear in
the parameter attribute table even when they are defined in the function or
script. To help users, provide this information in the parameter description.
正如@KeithHill所指出的那样,似乎将在下一个修订版中修复