Alex Young
asked on
Powershell Hyperlinks
Hi,
I'm trying to embed a hyperlink in a html table this is the line of code.
$result | Add-Member -MemberType NoteProperty -Name 'More Detail' -Value "<a href='$comp.html'>$comp</a >" | ConvertTo-HTML -Fragment
and the formatting is
$a = "<style>"
$a = $a + "BODY{background-color:whi te;
font-family:Tahoma;
font-size:7pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding:0px;border-sty le: solid;border-color: black;background-color:thi stle}"
$a = $a + "TD{border-width: 1px;padding:0px;border-sty le: solid;border-color: black;background-color:pal egoldenrod ;a:link.na vlink { color:#0000cc }"
$a = $a + "</style>"
$a = $a + "</FONT>"
But the hyperlink is not working i'm just seeing the following
More Detail
<a href='Alex-PC.html'>Alex-P C</a>
any advice on getting the hyperlink working
I'm trying to embed a hyperlink in a html table this is the line of code.
$result | Add-Member -MemberType NoteProperty -Name 'More Detail' -Value "<a href='$comp.html'>$comp</a
and the formatting is
$a = "<style>"
$a = $a + "BODY{background-color:whi
font-family:Tahoma;
font-size:7pt;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding:0px;border-sty
$a = $a + "TD{border-width: 1px;padding:0px;border-sty
$a = $a + "</style>"
$a = $a + "</FONT>"
But the hyperlink is not working i'm just seeing the following
More Detail
<a href='Alex-PC.html'>Alex-P
any advice on getting the hyperlink working
I think I need more detail. I don't see where $a is relevant to the question. What are you wanting to see from the link?
ASKER
Thought you might need to see the formatting incase i'm missing something, I have got all the data for computers coming in a table but one of the colums is a hyperlink which is generated by another script to collect the software on that particular computer.
So when it runs you should be able to click on the link on the hardware inventory and it will link to that relevent $comp variable.html, I'm now rethinking it but not sure how to get the data in SQL so learning that - Would you suggest that putting the data into a SQL DB be easier to pull out these kind of reports?
So when it runs you should be able to click on the link on the hardware inventory and it will link to that relevent $comp variable.html, I'm now rethinking it but not sure how to get the data in SQL so learning that - Would you suggest that putting the data into a SQL DB be easier to pull out these kind of reports?
Maybe the issue is the use of single quotes. You might try
$result | Add-Member -MemberType NoteProperty -Name 'More Detail' -Value "<a href=""$comp.html"">$comp< /a>" | ConvertTo-HTML -Fragment
I hardly ever use SQL I wouldn't be the best to advise you.
$result | Add-Member -MemberType NoteProperty -Name 'More Detail' -Value "<a href=""$comp.html"">$comp<
I hardly ever use SQL I wouldn't be the best to advise you.
OK, I see what is happening. ConvertTo-HTML is treating the <, >, and " characters as literal. Found a webpage that described this at http://jdhitsolutions.com/blog/2012/04/create-an-html-powershell-help-page/
On the page it just mentioned < and > characters, but in my testing " was also converted. So I modified his function. You will be able to pipe HTML to it fix the characters as shown on the last line.
On the page it just mentioned < and > characters, but in my testing " was also converted. So I modified his function. You will be able to pipe HTML to it fix the characters as shown on the last line.
Function Convert-HTMLEscape {
<#
Convert < and > to < and >
It is assumed that these will be in pairs
Also convert $quot; to "
#>
[cmdletbinding()]
Param (
[Parameter(Position=0,ValueFromPipeline=$True)]
[string[]]$Text
)
Process
{
foreach ($item in $Text)
{
if ($item -match "<")
{
(($item.Replace("<","<")).Replace(">",">")).Replace(""",'"')
}
else
{
#otherwise just write the line to the pipeline
$item
}
}
} #close process
} #close function
$result | Add-Member -MemberType NoteProperty -Name 'More Detail' -Value "<a href=""$comp.html"">$comp</a>" | ConvertTo-HTML -Fragment | Convert-HTMLEscape
ASKER
Hi, Thanks for that but still same issue for some reason it's picking up the variable so changes that to the correct computers but it's displaying the following
<a href="Alex-PC.html">Alex-P C</a>
It's so random if i take away the css formatting it all works i'm just wondering if something is wrong with that line of code.
Would it help if i show the whole code?
<a href="Alex-PC.html">Alex-P
It's so random if i take away the css formatting it all works i'm just wondering if something is wrong with that line of code.
Would it help if i show the whole code?
Perhaps. I think the HTML would be more helpful (at least a couple lines relevant to the link).
ASKER
I've attached - it's got some of me testing but see if you can figure it out its driving me mad lol something so simple :)
Full-HardwareSoftware---Copy.txt
Full-HardwareSoftware---Copy.txt
Thanks. How about the HTML source (at least part of it that is relevant)?
ASKER
ah sorry, here it is the line for the hyperlink
<td><a href="Alex-PC.html&qu ot;>Ale x-PC</a ></td>< /tr>
</table>
</body></html>
<td><a href="Alex-PC.html&qu
</table>
</body></html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant!!! Solved It thank you so much knew it be something simple :) this is the working code
$results | ConvertTo-Html -Title "PC Inventory" -head $PCInvFormattingPage -Body $PCInvFormatting | Convert-HTMLEscape | Out-File $htmlFile
$results | ConvertTo-Html -Title "PC Inventory" -head $PCInvFormattingPage -Body $PCInvFormatting | Convert-HTMLEscape | Out-File $htmlFile