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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.