Powershell + HTML

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of H Man H Man 2 years, 4 months ago.

  • Author
    Posts
  • #17117
    Profile photo of H Man
    H Man
    Participant

    I am making a powershell report that generates a table presently the top part of the table is blue and font color is black , the body of the table is "whitesmoke"

     
    $color = 'Blue'
    $tableColor = "whitesmoke"
    
    # HTML Style Definition
    $REPORT = ""
    $REPORT = ""
    $REPORT = ""
    $REPORT = $REPORT + "TABLE{border-width:2px;border-style: solid;border-color: #C0C0C0 ;border-collapse: collapse;width: 100%}"
    $REPORT = $REPORT + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}"
    $REPORT = $REPORT + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}"
    $REPORT = $REPORT + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: #C0C0C0 ;text-align: left}"
    $REPORT = $REPORT + "H1{font-family:Calibri;}"
    $REPORT = $REPORT + "H2{font-family:Calibri;}"
    $REPORT = $REPORT + "Body{font-family:Calibri;}"
    $REPORT = $REPORT + ""
    
    # Title
    $REPORT = $REPORT + "MY SQL REPORT : $($filedate)"
    
    #Reboot
    $REPORT = $REPORT + "TH{background-color:$($color)}TR{background-color:$($tableColor)}"
    $REPORT = $REPORT + ($QUERY | ConvertTo-HTML -Fragment )  + " "
    
    $REPORT = $REPORT + ""
    
    
    

    I would like the font to be White does any one know how to adjust this so the font is white ?

  • #17121
    Profile photo of Sam Boutros
    Sam Boutros
    Participant

    see attached..

  • #17122
    Profile photo of Raymond Slieff
    Raymond Slieff
    Participant

    I try to use an in document style sheet, but it all depends on your comfort with CSS, here is an example I use on the Inactive AD Computer Report I generate.

    $HTMLhead = @"
    
    
        
            Inactive Computer Report
        
            body
            {
                background-color:#FAFAFA;
                font-family:Arial;
                font-size:12pt; 
            }
            td, th 
            { 
                border:1px solid black;
                border-collapse:collapse; 
            }
            th 
            { 
                color:white;
                background-color:black; 
            }
            table, tr, td, th 
            {
                padding: 2px; 
                margin: 0px 
            }
            tr:nth-child(odd) 
            {
                background-color: lightgray
            }
            table 
            {
                margin-left:10%;
                width:80%
            }
            img
            {
            float:left;
            margin: 0px 25px;
            }
            #footer
            {
                display:block;
                width:100%;
                text-align:center;
            }
            h2
            {
                text-align:center;
            }
        
    
    
    "@
    

    That being said, for a table all you should have to do is edit this line:

    $REPORT = $REPORT + "TABLE{border-width:2px;border-style: solid;border-color: #C0C0C0 ;border-collapse: collapse;width: 100%}"

    to be:

    $REPORT = $REPORT + " TABLE style='border-width:2px;border-style: solid;border-color: #C0C0C0 ;border-collapse: collapse;width: 100%; color:#FFFFFF' "

    edit: not sure if you are applying the CSS you list in any other way, so in my version I setup the table cell as straight HTML with inline CSS.
    multi-edits: because I kept trying to use angle brackets.

  • #17124
    Profile photo of H Man
    H Man
    Participant

    thanks guys. that worked perfectly

You must be logged in to reply to this topic.