2012-04-11 51 views
3

我想設置我的PowerShell命令,所以Get-Help -full將顯示關於如何運行腳本的完整信息。我有默認值,我想在這個幫助中顯示。我有以下內容: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 = "[email protected]" 
) 

但是,當我輸入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? 

如何獲得顯示該參數默認值的幫助?

回答

3

我不認爲你可以得到默認值顯示在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    [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 
+0

感謝您的答覆指出。我想我們會在升級到Windows 7時看到它。 – 2012-04-11 18:31:15

4

似乎沒有辦法指定參數的默認值。您需要在參數的描述中指定它。

<# 
.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 
#> 

本帖子中的信息已顯示在故障排除部分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

+0

感謝您的鏈接。自從他首先回復後,我已經給了KeithHill正確的答案。不過,我會爲你修改一個鏈接點。 – 2012-04-11 18:32:40