#PSTip Getting SharePoint 2010 Health Analyzer alerts report by email
SharePoint 2010 administrators are probably familiar with the following screenshot–you open the Central Administration page and you’re presented with a red Health Analyzer alert.
Clicking the ‘View these issues’ link takes you to a page that lists all items that needs an attention.
Checking the health alerts page each day can be a daunting task and you might also forget to do so. To avoid that, and to enable multiple team members to be aware of the alerts, you can send the alerts by email. The Health list view (All Reports) is configured to list all items with a Severity not equal to Success (4).
Using the following code, you can read all items, and generate an email that you can send to your team members. Put it in a daily scheduled task on the SharePoint server and you’re good to go.
if ($PSVersionTable) {$Host.Runspace.ThreadOptions = 'ReuseThread'}
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# get the health reports list
$ReportsList = [Microsoft.SharePoint.Administration.Health.SPHealthReportsList]::Local
$FormUrl = '{0}{1}?id=' -f $ReportsList.ParentWeb.Url, $ReportsList.Forms.List.DefaultDisplayFormUrl
$body = $ReportsList.Items | Where-Object {$_['Severity'] -ne '4 - Success'} | ForEach-Object {
New-Object PSObject -Property @{
Url = "<a href='$FormUrl$($_.ID)'>$($_['Title'])</a>"
Severity = $_['Severity']
Category = $_['Category']
Explanation = $_['Explanation']
Modified = $_['Modified']
FailingServers = $_['Failing Servers']
FailingServices = $_['Failing Services']
Remedy = $_['Remedy']
}
} | ConvertTo-Html | Out-String
# creating clickable HTML links
$body = $body -replace '<','<' -replace '>','>' -replace '"','"'
$params = @{
To = 'you@domain.com','manager@domain.com'
From = 'SPHealth@domain.com'
Subject = 'Daily Health Analyzer report'
SmtpServer = 'smtp1'
Body = $body
BodyAsHtml = $true
}
Send-MailMessage @params
This is how it looks in Outlook (partial view).
Share on: