Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 465
Steve Guidi Avatar asked Jul 21 '11 22:07

Steve Guidi


People also ask

How do I set a default parameter in PowerShell?

To set default values for multiple parameters, separate each Key/Value pair with a semicolon ( ; ). The Send-MailMessage:SmtpServer and Get-WinEvent:LogName keys are set to custom default values.

How do I pass parameters to a PowerShell script?

How do I pass parameters to PowerShell scripts? Passing arguments in PowerShell is the same as in any other shell: you just type the command name, and then each argument, separated by spaces. If you need to specify the parameter name, you prefix it with a dash like -Name and then after a space (or a colon), the value.

How do you prompt a parameter in PowerShell?

A: You can prompt for user input with PowerShell by using the Read-Host cmdlet. The Read-Host cmdlet reads a line of input from the PowerShell console. The –Prompt parameter enables you to display a string of text. PowerShell will append a colon to the end of the string.

What does $? Mean in PowerShell?

$? Contains the execution status of the last command. It contains True if the last command succeeded and False if it failed. For cmdlets and advanced functions that are run at multiple stages in a pipeline, for example in both process and end blocks, calling this.


1 Answers

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

like image 173
JasonMArcher Avatar answered Oct 19 '22 07:10

JasonMArcher