5

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

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

4

2 回答 2

5

我认为您无法在 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
于 2012-04-11T17:36:46.493 回答
3

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

<#
.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 所指出的,似乎将在下一个修订版中修复

于 2012-04-11T17:40:02.223 回答