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)

Powershell script to find clusters in active directory domain,ping them and send result as html file

#To run the scripts you need to change execution policy
set-executionpolicy unrestricted

#Below cluster commands are part of fail over clusters module.Load this module #before executing cluster cmdlets
Import-module failoverclusters

# delete previous days check

del “c:\logs\ServerStatus.htm”

$OutputFile = “c:\logs\ServerStatus.htm”

#Get-cluster fetches clusters from AD domain and sends the output to $servers as input
$servers = get-cluster -domain domain_name

$Result = $()

foreach ($server in $servers)
{
$status = @{ “ServerName” = $server; “TimeStamp” = (Get-Date -f s) }
if (Test-Connection $server -Count 1 -ea 0 -Quiet)
{
$status[“Results”] = “Up”
}
else
{
$status[“Results”] = “Down”
}
New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
$Result += $serverStatus

}

if($Result -ne $null)
{
$HTML = ‘
#Header{font-family:”Trebuchet MS”, Arial, Helvetica, sans-serif;width:100%;border-collapse:collapse;}
#Header td, #Header th {font-size:14px;border:1px solid #98bf21;padding:3px 7px 2px 7px;}
#Header th {font-size:14px;text-align:left;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#fff;}
#Header tr.alt td {color:#000;background-color:#EAF2D3;}

$HTML += “






Foreach($Entry in $Result)
{
if($Entry.Results -ne “UP”)
{
$HTML += “”
}
else
{
$HTML += “”
}
$HTML += ”




}
$HTML += “

$HTML | Out-File $OutputFile
}

# Send Final Report by email…

Write-Host “Emailing Report”
$SMTPServer =”smtp_FQDN_servername”
$Body = ConvertTo-HTML -head $Head -body “$HTML”
$SmtpClient = New-Object Net.Mail.SmtpClient($smtpServer);
$mailmessage = New-Object system.net.mail.mailmessage
$mailmessage.from = “Clusters@domain_name”
$mailmessage.To.add(“server_team_email_address”)
$mailmessage.To.add(“Team2”)
$mailmessage.cc.add(“Manager_email_address”)
$mailmessage.Subject = “Clusters Uptime Report”
$MailMessage.IsBodyHtml = $true
$mailmessage.Body = $Body
$smtpclient.Send($mailmessage)

Powershell script to find clusters in a domain and send the result as attachment

# delete previous days check
#clusters.xls is the output file that contains cluster list in a domain
del “c:\logs\clusters.xls”

get-cluster -domain domainname > c:\logs\clusters.xls

send-mailmessage -from “email_address” -to “receiever_email_address” -cc “additional_receiepent” -subject “Clusters in domain” -Body “This attachment contains cluster names in domain” -Attachments “clusters.xls” -priority High -dno onSuccess, onFailure -smtpServer smtpservername