torsdag den 18. juli 2013

Daily health report by mail - SharePoint 2010

Found a script that sends a email with the SharePoint Health report. Its useful when you want the information delivered to your inbox instead of going to each SharePoint environment and checking the health report there. Put the script below, into a scheduled task and run it daily:

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 = "$($_['Title'])"
        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


Source: Shay Levy

Ingen kommentarer:

Send en kommentar