Reputation: 37
I am trying to generate a HTML report using powershell. I use ConvertTo-html & is working fine. However, I need to pass some values with HTML tags such as <.br.> to the cell values in the HTML table. Unfortunately the tags are converted to "&.lt.;" and "&.gt.;" when generating the html file. I tried to avoid this with [System.Net.WebUtility]::HtmlDecode and also by -replace function. But none is working. Is there any other way to avoid this conversion?
`$table1 = New-Object System.Data.DataTable
$table1 .Columns.Add("Parameter","string")
$table1 .Columns.Add("Value","string")
$row1 = $table1.NewRow()
..............
..............
$row1.Value = "Some Value here <BR>"
$table1 | Select-Object * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors | ConvertTo-html -Body $BodyText >> "$filepath\$name.html"`
=================================================================
Upvotes: 0
Views: 1290
Reputation: 37
Found the answer. Added a string tag replacement to the last line as below.
$table1 | Select-Object * -ExcludeProperty RowError, RowState, Table, ItemArray, HasErrors | ConvertTo-html -Body "<H2> Header Text </H2>" | foreach { $PSItem -replace "-linebreak-", "<BR>" } >> "$filepath\$name.html"
Upvotes: 1