Author Posts

August 21, 2013 at 7:45 am

When using ConvertTo-HTML with no input object and only -body and -head tags, the output contains a trailing set of empty

tags. This causes some minor graphical glitching when emailing the contents via Outlook. Apart from dumping the output to a string and manually searching/replacing the empty tags, is there an option that will suppress this spurious tag?

Sample code:

$a = Get-Process |Convertto-html -fragment
$b = Get-service |Convertto-html -fragment
convertto-html -body "$a $b"

This comes up a lot for me as my usual flow is to build up a report in pieces and then to combine the report segments with CSS via a final ConvertTo-HTML with -body and -head tags for style application.


August 21, 2013 at 7:49 am

There is no option to do so, no. It'd be listed in the command's help if there was. I'd say a workaround might be to pass the string   (non-breaking space) to -InputObject, but I haven't tried that. I often do the same process (and wrote about it in the ebook on HTML reporting), but never ran into the blank table being a problem. It'd certain be easy enough to -replace out. You might also look at the EnhancedHTML module I wrote and see if that works any better for you. It's part of the ebook (go to the Newsletter page here for the download).