Powershell script that will e-mail list of unhealthy SCOM agents

Below is a really useful script that will output a list of SCOM agents that are not healthy in your management group and e-mail this list to specified addresses. All you need to do is amend the SMTP client host and target to and from e-mail addresses to suit your own requirements. (Parts highlighted in green)

$Head = “<style>”
$Head +=”BODY{background-color:#CCCCCC;font-family:Verdana,sans-serif; font-size: x-small;}”
$Head +=”TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; width: 100%;}”
$Head +=”TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:green;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:#F0F0F0; padding: 2px;}”
$Head +=”</style>”

Set-Location Monitoring:

write-host “Getting Agent Health Status” -ForegroundColor Yellow
$ReportOutput += “<h2>Agents where Health State is not Green</h2>”
$ReportOutput += Get-Agent | where {$_.HealthState -ne “Success”} | select Name,HealthState | ConvertTo-HTML -fragment

$Body = ConvertTo-HTML -head $Head -body “$ReportOutput”
$SmtpClient = New-Object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$mailmessage.from = “scom.report@scom.com
$mailmessage.Subject = “SCOM Agents that are not Healthy”
$MailMessage.IsBodyHtml = 1
$mailmessage.Body = $Body

This entry was posted in Misc Stuff, Powershell for SCOM, SCOM Agents and tagged , , , , , , , . Bookmark the permalink.

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