Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Change html text color inline

$
0
0

Hey all so I have a script the pings some machines and adds them to a html file as well as a log file if I can't reach them. However I want to make the machines that have been offline for more than 3 times to turn red in the html table and the others to remain white. I have a header that makes them white by default but I guess for each one I want to turn red I need to do an inline font color. I'm just not sure the syntax of that.

$head = "<style>"
$head = $head + "BODY{background-color:#000066;}"
$head = $head + "h2{color:white;text-align:center;}"
$head = $head + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;margin-left: auto;margin-right: auto;}"
$head = $head + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: grey;background-color:#999966;color: white;}"
$head = $head + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: grey;background-color:#00066;color: white;text-align: center;}"
$head = $head + "a{text-decoration:none;color:white;}"
$head = $head + "ul{color:white;}"
$head = $head + "</style>"
$head = $head + '<ul><li><a href="/WakeOnLanReport1.html">First Floor </a></li>'
$head = $head + '<li><a href="/WakeOnLanReport2.html">Second Floor</a></li>'
$head = $head + '<li><a href="/WakeOnLanReport3.html">Third Floor </a></li>'
$head = $head + '<li><a href="/WakeOnLanReport232.html">Engineering</a></li></ul>'

#checks to see if machine is still off if so writes it to log file and webfile
foreach($machine in $machines){
    $info = -split $machine
    if(!(Test-Connection -ComputerName $info[0] -BufferSize 16 -Count 1 -ea 0 -quiet)){
        $problems = Get-Content -Path C:\users\Public\Documents\www\2ndlog.log -TotalCount $line |Select-String -Pattern $info[0]
        if($problems.length -ge 2){
            $obj = New-Object System.Object
            $obj | Add-Member -MemberType NoteProperty ComputerName -Value $info[0]
            $obj | Add-Member -MemberType NoteProperty Awake -value $false
            $results += $obj
        }else{
            #adds machine to webfile
            $obj = New-Object System.Object
            $obj | Add-Member -MemberType NoteProperty ComputerName -Value $info[0]
            $obj | Add-Member -MemberType NoteProperty Awake -value $false
            $results += $obj
        }
        #adds computer name to log file if it fails after each iteration
        Add-Content -Path "C:\Users\Public\Documents\www\temp2.log" -Value $info[0]
    }
}

#converts result to html and adds the webfile to it
$results  |ConvertTo-Html -head $head -body "<H2>Wake on lan Report as of $end </H2>"  | Out-File $webfile

There are 2 different add members, one that I want red and the other white. I have already tried putting -Value "<font color='red'>$($info[0])</font>" with no luck.

Thanks for any help!




Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>