locked
ConvertTo-HTML w/ Hyperlinks RRS feed

  • Question

  • I am trying to output a list of our Network Printers from the Printer Server to an HTML Page. I want to have one of the columns contain a clickable link that takes you to the printers web managment page. How can I do a hyperlink w/ ConvertTo-HTML?


    $printers = Get-WmiObject -Class Win32_Printer -ComputerName .
    $printers | Select-Object Name, Location, DriverName, @{Name="PortName";Expression={($_.Portname.SubString(3))}}, @{Name="Link";Expression={("<link rel=" + $_.Portname.SubString(3) + " href=http://" + $_.Portname.SubString(3)) + "/>"}} | Sort-Object Name |  ConvertTo-Html -Body $_ -Title "Printer List" -CssUri C:\Style.css | Out-File Printers.html
    

    Wednesday, March 28, 2012 11:13 AM

Answers

  • Hi,

    Try that:

    $printers = Get-WmiObject -Class Win32_Printer -ComputerName .
    $printers | Select-Object Name, Location, DriverName, @{Name="PortName";Expression={($_.Portname.SubString(3))}}, @{Name="Link";Expression={("<a rel=" + $_.Portname.SubString(3) + " href=http://" + $_.Portname.SubString(3)) + ">" + $_.Portname.SubString(3) + "</a>"}} | Sort-Object Name |  ConvertTo-Html -Body $_ -Title "Printer List" -CssUri C:\Style.css | %{$tmp = $_ -replace "&lt;","<"; $tmp -replace "&gt;",">";} |Out-File p:\Printers.html

    Wednesday, March 28, 2012 11:42 AM

All replies

  • Hi,

    Try that:

    $printers = Get-WmiObject -Class Win32_Printer -ComputerName .
    $printers | Select-Object Name, Location, DriverName, @{Name="PortName";Expression={($_.Portname.SubString(3))}}, @{Name="Link";Expression={("<a rel=" + $_.Portname.SubString(3) + " href=http://" + $_.Portname.SubString(3)) + ">" + $_.Portname.SubString(3) + "</a>"}} | Sort-Object Name |  ConvertTo-Html -Body $_ -Title "Printer List" -CssUri C:\Style.css | %{$tmp = $_ -replace "&lt;","<"; $tmp -replace "&gt;",">";} |Out-File p:\Printers.html

    Wednesday, March 28, 2012 11:42 AM
  • Great thanks!

    Wednesday, March 28, 2012 12:18 PM
  • Michal,

    I wasn't able to get the link to appear in the HTML file and edited the "LINK" expression as follows: 

    {L="Link";Expression={("<a href=`"http://" + $_.Portname.SubString(3)) +"`">" + $_.Portname.SubString(3) + "</a>"}}

    Do you really need the <a rel html code or would the above code work just as well?

    ( Note: I did remove the -CssUri paramater\value...not sure if that makes the difference in using <a rel )

    Joe

    Wednesday, March 28, 2012 12:58 PM