Concerning ConvertTo-Html

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Jarl F. Jarl F. 6 months ago.

  • Author
    Posts
  • #54578
    Profile photo of Jarl F.
    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 6 months ago by Profile photo of Jarl F. Jarl F..
  • #54580
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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
      Profile photo of Jarl F.
      Jarl F.
      Participant

      Thanks, Daniel!

You must be logged in to reply to this topic.