platyPS icon indicating copy to clipboard operation
platyPS copied to clipboard

Export-MamlCommandHelp doesn't include default value for parameter

Open pewill opened this issue 4 months ago • 2 comments

Prerequisites

  • [x] Write a descriptive title.
  • [x] Make sure you are able to repro it on the latest version
  • [x] Search the existing issues.

Steps to reproduce

I try to include parameter default values documentation using PlatyPS but I can't get it to work. It seems like the default values are not populated by New-CommandHelp and even if they are set explicitly on the CommandHelp object or in the markdown file it seems the value is not picked up by Export-MamlCommandHelp and are missing in the generated MAML file. Repro steps

function Get-Foo {
    param(
        [String] $Name = 'bar'
    )

    "Foo $Name"
}

$cmdHelp = get-command get-foo | New-CommandHelp
$cmdHelp.ToMarkdownString() # note that default value is empty

$cmdHelp.Parameters[0].DefaultValue = "bar" # set the default value explicitly
$cmdHelp.ToMarkdownString() # verify default value is correct
$cmdHelp | Export-MamlCommandHelp -OutputFolder . -force # create maml file. This will not contain the default value
Get-Content .\Get-Foo-Help.xml # notice that there is no <dev:defaultValue>bar</dev:defaultValue> element
Show-HelpPreview -Path .\Get-Foo-Help.xml # notice the missing default value


Expected behavior

NAME
    Get-Foo

SYNOPSIS
    {{ Fill in the Synopsis }}


SYNTAX
    Get-Foo [-Name <System.String>] [<CommonParameters>]


DESCRIPTION
    {{ Fill in the Description }}


PARAMETERS
    -Name [<System.String>]
        {{ Fill Name Description }}

        Required?                    false
        Position?                    0
        Default value                bar
        Accept pipeline input?       false
        Aliases                      none
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS
    System.Object
        {{ Fill in the Description }}


NOTES


        {{ Fill in the Notes }}

    --------- Example 1 ---------

    {{ Add example description here }}


RELATED LINKS
    Online Version

Actual behavior

NAME
    Get-Foo

SYNOPSIS
    {{ Fill in the Synopsis }}


SYNTAX
    Get-Foo [-Name <System.String>] [<CommonParameters>]


DESCRIPTION
    {{ Fill in the Description }}


PARAMETERS
    -Name [<System.String>]
        {{ Fill Name Description }}

        Required?                    false
        Position?                    0
        Default value
        Accept pipeline input?       false
        Aliases                      none
        Accept wildcard characters?  false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer, PipelineVariable, and OutVariable. For more information, see
        about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).

INPUTS

OUTPUTS
    System.Object
        {{ Fill in the Description }}


NOTES


        {{ Fill in the Notes }}

    --------- Example 1 ---------

    {{ Add example description here }}


RELATED LINKS
    Online Version

Error details


Environment data

Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

1.0.1

Visuals

No response

pewill avatar Aug 13 '25 10:08 pewill

This is by design. The default value is not discoverable.

PS> (gcm Get-Foo).Parameters.Name

Name            : Name
ParameterType   : System.String
ParameterSets   : {[__AllParameterSets, System.Management.Automation.ParameterSetMetadata]}
IsDynamic       : False
Aliases         : {}
Attributes      : {, System.Management.Automation.ArgumentTypeConverterAttribute}
SwitchParameter : False

PS> (gcm Get-Foo).Parameters.Name.Attributes

ExperimentName                  :
ExperimentAction                : None
Position                        : 0
ParameterSetName                : __AllParameterSets
Mandatory                       : False
ValueFromPipeline               : False
ValueFromPipelineByPropertyName : False
ValueFromRemainingArguments     : False
HelpMessage                     :
HelpMessageBaseName             :
HelpMessageResourceId           :
DontShow                        : False
TypeId                          : System.Management.Automation.ParameterAttribute

TransformNullOptionalParameters : True
TypeId                          : System.Management.Automation.ArgumentTypeConverterAttribute

sdwheeler avatar Aug 19 '25 13:08 sdwheeler

The default value is not discoverable. However, the MAML that is being created is not quite right.

Need to compare the maml from the old and new versions of PlatyPS. maml-files.zip

Reopening.

sdwheeler avatar Aug 19 '25 14:08 sdwheeler