Skip to content

Get-Help shows incorrect spacing and unwanted prefixes for first line of .EXAMPLE text #23814

@daverayment

Description

@daverayment

Prerequisites

Steps to reproduce

I am writing a PowerShell module and adding help text for each of my exported cmdlets.

Several of my commands include multi-line examples, showing the command usage and example output, e.g.:

.EXAMPLE
PS> $devices = Get-MTPDeviceList
PS> if ($devices) { $devices[0].Name }
"My Phone"

.EXAMPLE
# Some explanatory text about the example.
PS> Get-MTPDeviceList

Name        Type
----        ----
Some Phone  Mobile Phone

I have tested my module in both Visual Studio Code's PowerShell terminal and also a separate instance of PowerShell in Terminal. When calling Get-Help Get-MTPDeviceList with switches that show example text (e.g. -Full or -Examples), the formatting of the displayed examples text is incorrect.

Specifically:

  1. Any leading spaces between the "PS>" and the rest of the string on the first line is removed.
  2. If the first line of an example is a comment (with or without a leading #), the text "PS >" is inserted before it.

Expected behavior

The following output should be displayed in the examples section when Get-Help -Full is called:

    -------------------------- EXAMPLE 1 --------------------------

    PS> $devices = Get-MTPDeviceList
    PS> if ($devices) { $devices[0].Name }
    "My Phone"






    -------------------------- EXAMPLE 2 --------------------------

    # Some explanatory text about the example.
    PS> Get-MTPDeviceList

    Name        Type
    ----        ----
    Some Phone  Mobile Phone

Actual behavior

The following is output. Note the removal of the space character in the first line of the first example and the insertion of the text "PS >" in the first line of the second example.

    -------------------------- EXAMPLE 1 --------------------------

    PS>$devices = Get-MTPDeviceList
    PS> if ($devices) { $devices[0].Name }
    "My Phone"






    -------------------------- EXAMPLE 2 --------------------------

    PS > # Some explanatory text about the example.
    PS> Get-MTPDeviceList

    Name        Type
    ----        ----
    Some Phone  Mobile Phone

Error details

No response

Environment data

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

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Interactive-HelpSystemhelp infrastructure and formatting of help

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions