Adding comment into function breaks get-help parameter output

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 3 years, 7 months ago.

  • Author
    Posts
  • #11662
    Profile photo of Alex Verboon
    Alex Verboon
    Participant

    Hey there,

    Hope someone can help me with this one. I have the following code
    Function Get-xos{

    [CmdletBinding()]
    Param (
    [Parameter(Mandatory=$True,
    ValueFromPipeline=$true,
    ValueFromPipelineByPropertyName=$true,
    HelpMessage= 'One or more computer names')]
    [Alias('Host')]
    [String[]]$ComputerName
    )
    Begin{}
    Process
    {
    ForEach($c in $ComputerName)
    {
    $os = Get-WmiObject -ComputerName $c -Class Win32_OperatingSystem
    $Prop = [ordered]@{
    "OSVersion" = $os.Version
    "OSBuild" = $os.BuildNumber
    }
    $Obj=New-Object -TypeName PSObject -Property $Prop
    Write-Output $obj
    }
    }
    End{}
    }

    when i then run
    get-help Get-xos -Parameter computername

    i get the following output
    -ComputerName
    One or more computer names

    Required? true
    Position? 0
    Accept pipeline input? true (ByValue, ByPropertyName)
    Parameter set name (All)
    Aliases Host
    Dynamic? false

    exactly what i want and as expected.

    But if i then add a comment to the function

    Function Get-xos{
    < # .DESCRIPTION Get OS version information #>
    ...............

    and run the same command, i get the following output

    defaultValue :
    parameterValue : String[]
    name : ComputerName
    type : @{name=String[]}
    required : true
    globbing : false
    pipelineInput : true (ByValue, ByPropertyName)
    position : 1

    what am I doing wrong. I want to create a ps1 file with multiple functions, and add comments , a description to each function. I have also tried to add the comment block right above the function, but that does not make a difference.

    Any help is appreciated.
    Alex

  • #11664
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Looks like maybe the engine doesn't bother displaying the HelpMessage property if you have a comment-based help block. There are two ways you can get this working (depending on your personal preference). You can add a .PARAMETER item to your comment-based help block, or you can put in-line comments in the param block itself. Here are examples of both:

    Function Get-xos{
        < #
         .DESCRIPTION
           Get OS version information
    
         .PARAMETER ComputerName
           One or more computer names
        #>
    
        [CmdletBinding()]
        Param (
            [Parameter(Mandatory=$True,
                       ValueFromPipeline=$true,
                       ValueFromPipelineByPropertyName=$true)]
            [Alias('Host')]
            [String[]]$ComputerName
        )
    
    # ... etc
    }
    
    Function Get-xos{
        < #
         .DESCRIPTION
           Get OS version information
        #>
    
        [CmdletBinding()]
        Param (
            # One or more computer names
            [Parameter(Mandatory=$True,
                       ValueFromPipeline=$true,
                       ValueFromPipelineByPropertyName=$true)]
            [Alias('Host')]
            [String[]]$ComputerName
        )
    
    # ... etc
    }
    

You must be logged in to reply to this topic.