Moose
Moose

Reputation: 23

convertto-html outputting character codes instead of the characters

hi i wrote a simple script for outputting the quickfixengineering in html but something is not realy working as pleased.

$qfe = gwmi -class win32_quickfixengineering
$qfe | select-object -property HotFixID, Description, Caption, 
@{LABEL="URL"; EXPRESSION={ "<a href=""" + $_.caption + """>" + $_.caption + "</a>" } } |
ConvertTo-html -Head $style -body "<H2>Windows Update Information (quickfixengineering)
</H2><H3>Creation Date: $date  /  Entries found: $fixcount</H3> " |
Out-File $scriptpath\html\$file

my idea is to put the caption property in html link tags before converting it to html, but when it is actualy converted certain characters are converted to html character codes.

like so:

&lt;a href=&quot;http://go.microsoft.com/fwlink/?LinkId=133041&quot;&gt;http:
//go.microsoft.com/fwlink/?LinkId=133041&lt;/a&gt;

i tried several things. the '' characters arent realy helping me too (dont know how to call these in english.) if things arent literal enough alrdy these make it even more literal.

does anyone have an idea / can help me please sorting this out :) tnx

Upvotes: 1

Views: 2894

Answers (2)

CB.
CB.

Reputation: 60938

Try this:

$qfe = gwmi -class win32_quickfixengineering
$qfe | select-object -property HotFixID, Description, Caption, 
@{LABEL="URL"; EXPRESSION={ "<a href=""" + $_.caption + """>" + $_.caption + "</a>" } } |
ConvertTo-html -Head $style -body "<H2>Windows Update Information (quickfixengineering)
</H2><H3>Creation Date: $date  /  Entries found: $fixcount</H3> " |
% { ($_.Replace("&lt;","<")).Replace("&gt;",">").replace("&quot;",'"') }|
Out-File $scriptpath\html\$file

Upvotes: 0

Frode F.
Frode F.

Reputation: 54911

Try to decode it before saving:

$qfe = gwmi -class win32_quickfixengineering
$html = $qfe | select-object -property HotFixID, Description, Caption, 
@{LABEL="URL"; EXPRESSION={ "<a href=""" + $_.caption + """>" + $_.caption + "</a>" } } |
ConvertTo-html -Head $style -body "<H2>Windows Update Information (quickfixengineering)
</H2><H3>Creation Date: $date  /  Entries found: $fixcount</H3> "

#Decode lines with link and save
$html = $html | % { if($_ -match 'a href' ) { [System.Web.HttpUtility]::HtmlDecode($_) } else { $_ } }
$html | Out-File $scriptpath\html\$file

Upvotes: 4

Related Questions