Concerning ConvertTo-Html

This topic contains 2 replies, has 2 voices, and was last updated by  Jarl F. 1 year, 2 months ago.

  • Author
    Posts
  • #54578

    Jarl F.
    Participant

    Hello Community 😉

    I'm trying to format an output of the script and came across the ConvertTo-HTML cmdlet.

    This is my code.

    $a01 = "abc"
    $a02 = "def"
    -join ($a01, $a02)
    -join ($a02, $a01)

    I need to get the HTML table like this as an output of the script.

    ---------------
    | abc |  def |
    ----------------
    | def | abc |
    -------------

    Is that possible?

    • This topic was modified 1 year, 2 months ago by  Jarl F..
  • #54580

    Daniel Krebs
    Moderator

    The ConvertTo-Html cmdlet works best with custom objects.

    Example:

    $a01 = "abc"
    $a02 = "def"
    
    @(
        [PSCustomObject]@{
            Column1 = $a01
            Column2 = $a02
        }
        [PSCustomObject]@{
            Column1 = $a02
            Column2 = $a01
        }
    ) | ConvertTo-Html -Fragment
    
    • #54581

      Jarl F.
      Participant

      Thanks, Daniel!

You must be logged in to reply to this topic.