开发者

What is required for Powershell 2.0 to render a script's default parameter value in the help page?

I have the following simple script that accepts text as input and writes it to the host.

<#
.SYNOPSIS
    Writes the input string to the host.
.PARAMETER Text
    The text to write to the host.
#>

param([string]$text = "hello world!")
Write-Host $text

To render the help for this script, I execute the following command within a Powershell session, where write-text.ps1 is the name of this script.

get-help .\write-text.ps1 -full

In the following output, I am expecting to see the default value of the script's parameter listed in the help -- but I don't:

PARAMETERS
    -text <String>
        The text to write to the host.

        Required?                 开发者_如何转开发   false
        Position?                    1
        Default value
        Accept pipeline input?       false
        Accept wildcard characters?

What do I need to add or change in this script for the help-engine to render the default parameter value?


You can not show a default value using the comment based help. You need to make a MAML help file to do that.


Script-based help can be picky, might be as simple as that you have capitalized the variable in the help text, but not that variable itself. A long shot, I know...

An alternative that I prefer is to but the description next to the parameter:

<#
.SYNOPSIS
MumbleMumble

.DESCRIPTION
Even more MumbleMumble

.EXAMPLE
PS> MumbleMumble
#>

function MumbleMumble
{
   param
   (
      #The in-parameter for MumbleMumble, as text
      $text
   )

   ...
}

I like this approach because it puts the description next to the parameter - and because it seems to work :).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜