Concerning ConvertTo-Html

Welcome Forums General PowerShell Q&A Concerning ConvertTo-Html

This topic contains 2 replies, has 2 voices, and was last updated by

 
Inactive
2 years ago.

  • Author
    Posts
  • #54578

    Inactive
    Points: 0
    Rank: Member

    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?

  • #54580

    Moderator
    Points: 0
    Team Member
    Rank: Member

    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

      Inactive
      Points: 0
      Rank: Member

      Thanks, Daniel!

The topic ‘Concerning ConvertTo-Html’ is closed to new replies.