Dinesh Karunarathna
Dinesh Karunarathna

Reputation: 37

PowerShell converts html tags "<" and ">" to "<" and ">"

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?

This is the code I used

`$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

Answers (1)

Dinesh Karunarathna
Dinesh Karunarathna

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

Related Questions