Powershell HTML Table Color

# Create header for HTML Report

$Head = “<style>”
$Head +=”BODY{font-family:Calibri,sans-serif; font-size: small;}”
$Head +=”TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; width: 98%;}”
#$Head +=”TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#ff0000;color:white;padding: 5px; font-weight: bold;text-align:left;}”
#$Head +=”TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#ff0000; padding: 2px;}”
$Head +=”</style>”
$values = 1,2,3,4,5

$thold = 3

$output += “<table><th style = ‘text-align:left;’>Values</th>”

foreach ( $i in $values)
{

if ($i -le 3)

{

$output += “<tr><td style = ‘border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#ff0000; padding: 5px;’>Lower</td></tr>”

}
else
{

$output += “<tr><td style = ‘border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding: 5px;’>Upper</td></tr>”

}
}

$output += “</table>”

# Close the Body of the Report
$output += “</body>”

# Send Final Report by email…

Write-Host “Emailing Report”
$SMTPServer =””
$Body = ConvertTo-HTML -head $Head -body “$output”
$SmtpClient = New-Object Net.Mail.SmtpClient($smtpServer);
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = “”
#$mailmessage.To.add(“”)
#$mailmessage.To.add(“”)
$mailmessage.to.add(“”)
# Want more recipient’s? Just add a new line
#$mailmessage.To.add(“anotherrecipient@company.com”)
$mailmessage.Subject = “Disk Space Check Report”
$MailMessage.IsBodyHtml = $true
$mailmessage.Body = $Body
$smtpclient.Send($mailmessage)

Advertisements

Author: priyathamsystemcenterblog

I am system center operations manager & configuration manager administrator And has good knowledge in windows servers too.................................:)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s