1

I have a system array variable called $bodyab that looks like this:

VMName                      Name                                                CreationTime       
------                      ----                                                ------------       
SHARED-server.host.com      SHARED-server.host.com - (02/10/2017 - 13:02:44)    02/10/2017 13:05:58
Internal-Oliver-Cpanel      Internal-Oliver-Cpanel - (27/07/2018 - 14:10:31)    27/07/2018 14:10:33
UK-56084-89941-WIN          UK-56084-89941-WIN - (22/07/2018 - 20:06:10)        22/07/2018 20:06:17
UK-33776-50475-WIN          UK-33776-50475-WIN - (04/07/2018 - 11:25:26)        04/07/2018 11:25:33
UK-37741                    UK-37741_replica - (14/05/2018 - 16:05:13)      

I need to convert this to HTML but when I do

$bodyHtml = $bodyab | ConvertTo-Html

I get this output:

<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>ClassId2e4f51ef21dd47e99d3c952918aff9cd</th><th>pageHeaderEntry</th> 
<th>pageFooterEntry</th><th>autosizeInfo</th><th>shapeInfo</th> 
<th>groupingEntry</th></tr>
<tr><td>033ecb2bc07a4d43b5ef94ed5a35d280</td><td></td><td></td><td></td> 
<td>Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo</td><td>

rather than the table. I am really not sure what's going on at all.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
FrankU32
  • 311
  • 1
  • 3
  • 18

1 Answers1

2

OK I have worked this out myself. I was using Format-table earlier in the script to select specific attributes and pass them on in the pipeline. The problem is FT is only designed to use on visual output and causes errors like this if you use it in code.

The correct thing to do was to use Select-object in the code to select and pass the attributes of interest.

FrankU32
  • 311
  • 1
  • 3
  • 18