Powershell脚本默认值未显示在Get-Help -full中

时间:2012-04-11 17:24:16

标签: powershell parameters

我正在尝试设置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?

如何获取帮助以显示此参数的默认值?

2 个答案:

答案 0 :(得分:4)

我认为您无法在V2中的高级功能中显示默认值。我甚至没试过[System.ComponentModel.DefaultValueAttribute(“”)]。但是,如果有任何安慰,这似乎在V3中按原样工作。

V3 ONLY!!
PS> Get-Help .\help.ps1 -full

NAME
    C:\temp\help.ps1

SYNOPSIS

SYNTAX
    C:\temp\help.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

答案 1 :(得分:4)

似乎没有办法为参数指定默认值。您需要在参数的描述中指定它。

<#
.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所述,在下一版本中修复似乎