ConvertTo-HTML does not preserve single column heading

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Tim Curwick Tim Curwick 8 months, 1 week ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #34079
    Profile photo of Tim Curwick
    Tim Curwick
    Participant

    When an array of objects is piped to ConvertTo-HTML, it creates a table with the object property names as column headers. But if the objects only have a single property, the resultant table has an asterisk for the column header instead of the property name.

    # Example with two properties, expected behavior
    Get-Service Appi* | Select Name, Status | ConvertTo-HTML -Fragment
    

    Results in: (the web page trashes the resulting html here, but you get the idea)

    NameStatus
    AppIDSvcStopped
    AppinfoRunning

    #  Example with one property, undesired behavior
    Get-Service Appi* | Select Name | ConvertTo-HTML -Fragment
    

    Results in:

    *
    AppIDSvc
    Appinfo

    Is this a bug, or is this behavior desired for some reason that I am not understanding?

    #34100
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    According to a cursory search, this behaviour has been around for a while. I can't see a bug report for it on user voice though.

    The bug only rears its head if you pipe Select-Object to Convertto-HTML. You can have a single column if you use the -property parameter:

    Get-Service Appi* | ConvertTo-Html -Property Name -Fragment
    
    #34101
    Profile photo of Tim Curwick
    Tim Curwick
    Participant

    Matt,

    It was the lack of fixes or bug reports over the last few version of PowerShell that prompted me to ask the community if I was missing something before I posted a bug report.

    It shows the undesired behavior any time you pipe an array of objects with only one property to it without explicitly using the -Property parameter. (The Select statement was just a simple way to reproduce an object with a single property.)

    Thank you for the workaround.

    #34109
    Profile photo of Tim Curwick
    Tim Curwick
    Participant
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.