Skip to content

CommandHelp loaded by Import-MamlHelp generates incorrect syntax #816

@teramako

Description

@teramako

Prerequisites

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

Steps to reproduce

# cd path/to/project_dir
$cmdHelps = Import-MamlHelp -Path ./test/Pester/assets/Microsoft.PowerShell.Commands.Utility.dll-Help.xml
$cmdHelps[0].Title 
$cmdHelps[0].Syntax[0].SyntaxParameters = $cmdHelps[0].Syntax[0].SyntaxParameters | select -Unique  # *1
$cmdHelps[0].Syntax[0].ToString()
$cmdHelps[0].Syntax[0].SyntaxParameters | ft

*1: Each parameter is output in duplicate currently. This issue was reported in Issue #815.

  • Positional parameter syntax is wrong
  • Required parameter syntax is wrong
  • SwitchParameter parameter values should not be displayed

So

  • not [-MemberType <System.Management.Automation.PSMemberTypes>], should be [-MemberType] <System.Management.Automation.PSMemberTypes> (positional and mandatory)
  • not [-Name <System.String>], should be [-Name] <System.String> (positional and mandatory)
  • not [-Value <System.Object>], should be [[-Value] <System.Object>] (positional)
  • not [-InputObject <System.Management.Automation.PSObject>], should be -InputObject <System.Management.Automation.PSObject> (mandatory)
  • not [-Force <System.Management.Automation.SwitchParameter>], should be [-Force]

I think root cause is that the syntaxParameter values are not being read correctly from the Maml help (XML).

Expected behavior

Add-Member [-MemberType] <System.Management.Automation.PSMemberTypes> [-Name] <System.String> [[-Value] <System.Object>] [[-SecondValue] <System.Object>] -InputObject <System.Management.Automation.PSObject> [-Force] [-PassThru] [-TypeName <System.String>]



ParameterName ParameterType                                Position IsMandatory IsPositional IsSwitchParameter
------------- -------------                                -------- ----------- ------------ -----------------
MemberType    System.Management.Automation.PSMemberTypes   0               True         True             False
Name          System.String                                1               True         True             False
Value         System.Object                                2              False         True             False
SecondValue   System.Object                                3              False         True             False
Force         System.Management.Automation.SwitchParameter named          False        False              True
InputObject   System.Management.Automation.PSObject        named           True        False             False
PassThru      System.Management.Automation.SwitchParameter named          False        False              True
TypeName      System.String                                named          False        False             False

Actual behavior

Add-Member [-MemberType <System.Management.Automation.PSMemberTypes>] [-Name <System.String>] [-Value <System.Object>] [-SecondValue <System.Object>] [-Force <System.Management.Automation.SwitchParameter>] [-InputObject <System.Management.Automation.PSObject>] [-PassThru <System.Management.Automation.SwitchParameter>] [-TypeName <System.String>]



ParameterName ParameterType                                Position IsMandatory IsPositional IsSwitchParameter
------------- -------------                                -------- ----------- ------------ -----------------
MemberType    System.Management.Automation.PSMemberTypes                  False        False             False
Name          System.String                                               False        False             False
Value         System.Object                                               False        False             False
SecondValue   System.Object                                               False        False             False
Force         System.Management.Automation.SwitchParameter                False        False             False
InputObject   System.Management.Automation.PSObject                       False        False             False
PassThru      System.Management.Automation.SwitchParameter                False        False             False
TypeName      System.String                                               False        False             False

Error details

Environment data

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.5.2
PSEdition                      Core
GitCommitId                    7.5.2
OS                             Ubuntu 24.04.3 LTS
Platform                       Unix
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions