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”
$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 += “”
$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.Subject = “Clusters Uptime Report”
$MailMessage.IsBodyHtml = $true
$mailmessage.Body = $Body


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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s