title: How to format an object into a nice HTML table?
body: <p>I have 2 scripts</p>
  
  <p>script1 has the following:</p>
  
  <pre><code>$exportObject = New-Object System.Collections.ArrayList
  $exportObject | Select-Object
  </code></pre>
  
  <p>in script2, i am calling script1 to do something and piping the output to an <code>-ov</code></p>
  
  <pre><code>&amp; "script1.ps1" -ov $outputValue
  $outputValue
  </code></pre>
  
  <p>this is what i get</p>
  
  <p><a href="https://i.stack.imgur.com/EPUTS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EPUTS.png" alt="output"></a></p>
  
  <p>Now I am trying to send that variable output in an email body.</p>
  
  <pre><code>Send-MailMessage -From $FromEm -Subject $Subject -To "user@domain.com" -Body $outputValue -BodyAsHtml -SmtpServer $SmtpServer -Port $Port -Credential $Creds -UseSsl
  </code></pre>
  
  <p>Send_mailMessage won't accept ArrayList variable like this, so i am converting to HTML then string</p>
  
  <pre><code>$outputValue = $outputValue | ConvertTo-HTML &lt;# -As Table #&gt; | Out-String
  </code></pre>
  
  <p>this sends the following in the email body:</p>
  
  <p><a href="https://i.stack.imgur.com/toFan.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/toFan.png" alt="c"></a></p>
  
  <p>its good but i would like to make it look like a table, with borders styling, etc. </p>
  
  <p>how can i do that?</p>
  
  <p>i am thinking something like this:</p>
  
  <pre><code>$outputValue = $outputValue | ConvertTo-HTML | foreach-object{if($outValue.header) {&lt;th&gt;&lt;/th&gt;} else &lt;td&gt;&lt;/td&gt;} | Out-String
  </code></pre>
  
  <p>though thats a rough idea of what i have in mind and not sure how to do it exactly</p>