Powershell html formatting using convertto-html cmdlet

This was took me a little bit to figure out, but I finally did. Wasn't able to find this solution on the web so I figure I would post what I had to do to make it work. I basically had a 'if else' statement that I wanted the return of an if statement to highlight in red and be bolded in html. Unfortunately, the convertto-html cmdlet converts '<' and '>' to html friendly formats for display like '&lt;'and '&gt;'.

So here is the key:

foreach {$_.replace("&lt;","<").replace("&gt;",">")}

Afterwards, you can pipe to a file where the formatting you placed in your code stays intact.

1 comment:

Anonymous said...

Thanks a lot..!! I had the same issue and your solution worked well..!!!