Please feel free to provide feedback or file bugs here.

ConvertTo-Html incorrectly labels default single column

ConvertTo-Html works as desired when the output contains two or more columns.

ConvertTo-Html works as desired when the output contains only one column derived from a property that was explicitly named in the -Properties parameter.

However, if a match string is used for the -Property parameter, or the -Property parameter is omitted (and presumably defaults to match string "*"), and the output contains only a single column, the column header incorrectly contains the match string instead of the name of the property.

For example, this:

$X = [pscustomobject]@{ Name = 'Joe' }
ConvertTo-Html -InputObject $X -Fragment

Results in this:

<table>
<colgroup><col/></colgroup>
<tr><th>*</th></tr>
<tr><td>Joe</td></tr>
</table>

Additional examples and comparisons (results omitted)

# Examples with one property
$X = [pscustomobject]@{ Name = 'Joe' }

# Property selected by default, undesired result
ConvertTo-Html -InputObject $X -Fragment

# Property selected by match, undesired result
ConvertTo-Html -InputObject $X -Property * -Fragment
ConvertTo-Html -InputObject $X -Property N* -Fragment

# Property selected explicitly, desired result
ConvertTo-Html -InputObject $X -Property Name -Fragment

# Examples with two properties
$X = [pscustomobject]@{ Name = 'Joe'; Number = 21 }

# Property selected by default, desired result
ConvertTo-Html -InputObject $X -Fragment

# Property selected by match, desired result
ConvertTo-Html -InputObject $X -Property * -Fragment
ConvertTo-Html -InputObject $X -Property N* -Fragment

# Property selected explicitly, desired result
ConvertTo-Html -InputObject $X -Property Name, Number -Fragment

12 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Tim Curwick shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Cesar Quintana commented  ·   ·  Flag as inappropriate

        I'm experiencing this exact behavior. I thought I was crazy or an idiot. But, not, turns out I'm not... at least not when it comes to this specific issue! :D

      Feedback and Knowledge Base