Powershell Convertto-html bug

Dear expert

Im trying to export a query to html using powershell, now I use convertto-html command to exporting it... however when I check the html file, it shows on the
<tr><th>*</th></tr> now this is weird... after some searching I find out that when you select-object only one item, then convertto-html auto do this... its a bug from Micosoft, the bug was showing time 2016 first reported and after two years, still bugging.  

Enough with this sadly bug Im trying to found a solution for it, they say you could use -replace to remove the * to Header you want, now I have no idea how that work tho.

Any idea?
Thanks
LVL 1
WeTiAsked:
Who is Participating?
 
oBdACommented:
Sorry, copy and paste the pattern again (or remove the \A at the beginning and the \Z at the end), you were too fast ...
0
 
oBdACommented:
In the following example, the "Name" property has gone AWOL.
$fixPattern needs to remain unchanged.
$html = Get-Item C:\Windows | Select-Object Name | ConvertTo-Html
$fixPattern = '(?<=<tr><th>)\*(?=</th></tr>)'
$html = $html -replace $fixPattern, 'Name'

Open in new window

0
 
WeTiAuthor Commented:
$htmlout = $sqlArr | select-object 'PersonID' | convertto-html
$fixPattern = '\A(?<=<tr><th>)\*(?=</th></tr>)\Z'
$htmlout = $htmlout -replace $fixPattern, 'PersonID'
return $htmlout

Just to see the $htmlout result with return still same, the * is still there...
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
WeTiAuthor Commented:
As great as always oBdA, tell me man when can I be you? :) thanks alot, I will check the service PS script alittle bit more into it later, to improvement. Thanks for now.
0
 
WeTiAuthor Commented:
Just a simple question here if you still there:
'(?<=<tr><th>)\*(?=</th></tr>)'
what is this ?<= and what is this \*?
0
 
oBdACommented:
The -replace operator expects a "Regular Expression".
(?<=expression) is a "zero-width positive lookbehind"; it matches without consuming, since the tags should not be replaced.
Accordingly, (?=expression) is a "zero-width positive lookahead".
"*" is a "zero or more times" quantifier, so it needs to be escaped with a "\" when it should be matched as a character.
1
 
footechCommented:
Instead of modifying the HTML, a workaround is to just specify the single property to the -property parameter of ConvertTo-Html.
$htmlout = $sqlArr | convertto-html -property  'PersonID'

Open in new window

1
 
WeTiAuthor Commented:
$htmlout = $sqlArr | convertto-html -property  'PersonID' works as well, just tried :) wow.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.