The below script will monitor status of SharePoint user profile services timer jobs and email notification will be send to administrators
# -----------------------------------------------------------------------------
# Script : User Profile Jobs Daily Status Report
#------------------------------------------------------------------------------
#Add SharePoint PowerShell Snap-In
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$today=Get-Date
$WebApp = Get-SPWebapplication -identity "http://intranet.domain.com" #change your Url here..
function Get-SPTimerJobStatus ()
{
Get-SPTimerJob |sort Name |Where {$_.WebApplication.Name -eq "Intranet" -and $_.DisplayName -like "*User Profile*" } | ForEach-Object {
$lastRun = $_.HistoryEntries | Select-Object -first 1
if ($_.WebApplication -eq "$WebApp ") { $level = $_.WebApplication.Url }
else { $level = "Farm" }
$values = @{
"Name" = $_.Name
"Job Title" = $_.DisplayName
"SiteName" = $_.WebApplication.Name
"Level" = $level
"StartTime" = $lastRun.StartTime
"EndTime" = $lastRun.EndTime
"Status" = $lastRun.Status
"Schedule" = $_.Schedule
"Duration (HH:MM:SS)" = ($lastRun.EndTime - $lastRun.StartTime)
}
New-Object PSObject -Property $values | Select @("Job Title", "SiteName", "Schedule","StartTime","EndTime","Status", "Duration (HH:MM:SS)" )
}
}
$TimerJobStatus = Get-SPTimerJobStatus |ConvertTo-Html -Fragment
#-----------------------------------------------------------------------------------------
#Style Body
#-----------------------------------------------------------------------------------------
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{font-family:sans-serif;font-size:10pt;border-width:5px;border-style: solid;border-color: black;border-collapse: collapse;cellpadding:10px cellspacing:10px}"
$a = $a + "TH{border-width: 2px;padding: 3px;border-style: solid;border-color: black;background-color:blue}"
$a = $a + "TD{border-width: 2px;padding: 3px;border-style: solid;border-color: black;background-color:FFFAF0}"
$a = $a + "</style>"
ConvertTo-Html -head "$a" -Body "<font color = red><H2>Timer Jobs status Reports for $today</H2></font>$TimerJobStatus | Out-File "C:\Scripts\TimerJobsreport.txt" #change path here
#-----------------------------------------------------------------------------------------
#Send email to administrators
#-----------------------------------------------------------------------------------------
$Subject = "User profile Jobs status Reports for $today"
$To = "administrator@domain.com" #change email address here..
$From = "StatusReport@domain.com" #change from address here...
$SMTP = "smtp.domain.com" #change SMTP address here..
$SPReport = Get-Content "C:\Scripts\TimerJobsreport.txt"
Send-MailMessage -To $To -SmtpServer $SMTP -From $From -Subject $Subject -BodyAsHtml "$SPReport"
# -----------------------------------------------------------------------------
# Script : User Profile Jobs Daily Status Report
#------------------------------------------------------------------------------
#Add SharePoint PowerShell Snap-In
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$today=Get-Date
$WebApp = Get-SPWebapplication -identity "http://intranet.domain.com" #change your Url here..
function Get-SPTimerJobStatus ()
{
Get-SPTimerJob |sort Name |Where {$_.WebApplication.Name -eq "Intranet" -and $_.DisplayName -like "*User Profile*" } | ForEach-Object {
$lastRun = $_.HistoryEntries | Select-Object -first 1
if ($_.WebApplication -eq "$WebApp ") { $level = $_.WebApplication.Url }
else { $level = "Farm" }
$values = @{
"Name" = $_.Name
"Job Title" = $_.DisplayName
"SiteName" = $_.WebApplication.Name
"Level" = $level
"StartTime" = $lastRun.StartTime
"EndTime" = $lastRun.EndTime
"Status" = $lastRun.Status
"Schedule" = $_.Schedule
"Duration (HH:MM:SS)" = ($lastRun.EndTime - $lastRun.StartTime)
}
New-Object PSObject -Property $values | Select @("Job Title", "SiteName", "Schedule","StartTime","EndTime","Status", "Duration (HH:MM:SS)" )
}
}
$TimerJobStatus = Get-SPTimerJobStatus |ConvertTo-Html -Fragment
#-----------------------------------------------------------------------------------------
#Style Body
#-----------------------------------------------------------------------------------------
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{font-family:sans-serif;font-size:10pt;border-width:5px;border-style: solid;border-color: black;border-collapse: collapse;cellpadding:10px cellspacing:10px}"
$a = $a + "TH{border-width: 2px;padding: 3px;border-style: solid;border-color: black;background-color:blue}"
$a = $a + "TD{border-width: 2px;padding: 3px;border-style: solid;border-color: black;background-color:FFFAF0}"
$a = $a + "</style>"
ConvertTo-Html -head "$a" -Body "<font color = red><H2>Timer Jobs status Reports for $today</H2></font>$TimerJobStatus | Out-File "C:\Scripts\TimerJobsreport.txt" #change path here
#-----------------------------------------------------------------------------------------
#Send email to administrators
#-----------------------------------------------------------------------------------------
$Subject = "User profile Jobs status Reports for $today"
$To = "administrator@domain.com" #change email address here..
$From = "StatusReport@domain.com" #change from address here...
$SMTP = "smtp.domain.com" #change SMTP address here..
$SPReport = Get-Content "C:\Scripts\TimerJobsreport.txt"
Send-MailMessage -To $To -SmtpServer $SMTP -From $From -Subject $Subject -BodyAsHtml "$SPReport"