locked
Convertto-html with HTML code embedded RRS feed

  • Question

  • I would like to use Convertto-HTML but also add some HTML code in. Is this possible ?

     $f_tip = @{Name="Name";Expression = {"<a class='css_tooltip' href='#'> $_.name <span><table style='background: transparent; font-size: 11px;' align='center' border='0' cellpadding='2' cellspacing='0'><tr><td colspan='2' align='center'>TIPTOOL</a></td></tr></table></span></a>"}}
     
     $DCLISThtml=$dclist | sort Name | select Forest,Domain,$f_tip,IPAddress,SiteName,OSversion,CurrentTime,$f_roles | convertto-html -fragment

     

    Monday, February 7, 2011 8:20 PM

Answers

  • This isn't exaclty as easy as piping your object into the ConvertTo-HTML cmdlet, but here is a beautiful report for VMWare VirtualCenter that has a great technique to get the custom HTML you're looking for

    http://www.virtu-al.net/featured-scripts/vcheck/

    http://virtu-al.net/Downloads/vCheck/vCheck5.ps1

    Thanks to Alan Renouf for putting together such a nice script.


    -Beach
    • Marked as answer by Alan Zhu Monday, February 14, 2011 1:33 AM
    Wednesday, February 9, 2011 3:28 PM
  • I don't really mess with HTML much, but have you considered doing something like this instead:

    $body_hs = {
    @"
    <tr><td> $($item.PropertyName1) </td><td> $($item.PropertyName2) </td><td> $($item.PropertyName3) </td></tr>
    "@
    }

    $body = @()
    foreach ($item in $items){
    $body += &$body_hs
    }


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Marked as answer by Alan Zhu Monday, February 14, 2011 1:33 AM
    Wednesday, February 9, 2011 3:34 PM

All replies

  • you can use custom styles and change the format, liek this:

    http://technet.microsoft.com/en-us/library/ff730936.aspx

    http://powershell.com/cs/blogs/tips/archive/2009/03/20/creating-html-reports.aspx


    Thiyagu | MCTS/MCITP - Exchange 2007 | MCSE 2003[Messaging] | http://www.myExchangeWorld.com. This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, February 8, 2011 11:35 AM
  • How about something like this?

    $style = "<style>"
    $style = $style + "BODY{background-color:#8B8989;}"
    $style = $style + "TABLE{border-width: 1px;border-style: solid;border-color: #36648B;border-collapse: collapse;width: 100%}"
    $style = $style + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: #36648B;background-color:#A2B5CD}"
    $style = $style + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: #36648B;background-color:#C6E2FF;text-align: center}"
    $style = $style + "</style>"


    $body = "<H2>Some nice header label</H2><table><tr><th>Table header1</th><th>Table header2</th><th>Table header, you get the point</th></tr>"

    foreach($item in $items){
    $body  = $body  + "<tr><td>" + $item.PropertyName1 + "</td><td>" + $item.PropertyName2 + "</td><td>"+ $item.PropertyName3 + "</td></tr>"}

    $body  = $body  + "</table>"


    ConvertTo-HTML -head $style -Body $body | Set-Content $htmlFile

    That's how I've been doing it at least.


    -Beach
    Tuesday, February 8, 2011 6:10 PM
  • Stephen,

    Thank you for your answer, but this is exactly what I'm trying to avoid

    I may not have any other choice anyway

    Thank you

    PS: try $body  += "<tr><td>" + $item.PropertyName1 + "</td><td>" + $item.PropertyName2 + "</td><td>"+ $item.PropertyName3 + "</td></tr>"

     

     

     

    Wednesday, February 9, 2011 5:38 AM
  • Ahh, now I see what you're doing. I didn't read that carefully during the first pass. I do have some reports that I nest tables inside tables, but I'm building all the HTML with nested loops in order... as you said, what you're trying to avoid.

    Looking at your example, I believe you're getting an empty column (or just a null page) because of the select for $f_tip. Have you tried adding the $f_tip as a property to $dclist? Well, that will probably give you an extra column with your tool tip. You may want to add $f_tip to the dclist.Domain property and drop $f_tip from the select all together.


    -Beach
    Wednesday, February 9, 2011 2:22 PM
  • This isn't exaclty as easy as piping your object into the ConvertTo-HTML cmdlet, but here is a beautiful report for VMWare VirtualCenter that has a great technique to get the custom HTML you're looking for

    http://www.virtu-al.net/featured-scripts/vcheck/

    http://virtu-al.net/Downloads/vCheck/vCheck5.ps1

    Thanks to Alan Renouf for putting together such a nice script.


    -Beach
    • Marked as answer by Alan Zhu Monday, February 14, 2011 1:33 AM
    Wednesday, February 9, 2011 3:28 PM
  • I don't really mess with HTML much, but have you considered doing something like this instead:

    $body_hs = {
    @"
    <tr><td> $($item.PropertyName1) </td><td> $($item.PropertyName2) </td><td> $($item.PropertyName3) </td></tr>
    "@
    }

    $body = @()
    foreach ($item in $items){
    $body += &$body_hs
    }


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Marked as answer by Alan Zhu Monday, February 14, 2011 1:33 AM
    Wednesday, February 9, 2011 3:34 PM