Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Script Default Value not showing up in Get-Help -full

I am trying to setup my PowerShell command, so the Get-Help -full will show complete information about how to run my script. I have default values that I want to display in this help. I have the following:

<#
    .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 = "[email protected]"
)

Yet, when I type Get-Help -detail, the following shows up.

-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?

How do I get the help to show the default value of this parameter?

like image 934
David W. Avatar asked Apr 11 '12 17:04

David W.


2 Answers

I don't think you can get the default value to display in an advanced function in V2. I've even tried [System.ComponentModel.DefaultValueAttribute("")] with no luck. However, if it's any consolation, this appears to work as-is in 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                [email protected]
        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
like image 59
Keith Hill Avatar answered Sep 28 '22 04:09

Keith Hill


There does not seem to be a way to specify the default value for a parameter. You need to specify it in the parameter's description.

<#
.PARAMETER SenderEmail
The name of the user who is sending the email message. If not 
specified, a default value of [email protected] will be used
#>

This post has information in the trouble shooting section 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.

Seem's to be fixed in the next revision as noted by @KeithHill

like image 39
Grumsh Avatar answered Sep 28 '22 04:09

Grumsh