Get Timer Job history by Powershell

02/10/2018 11:00
Add-PSSnapin Microsoft.sharepoint.powershell
 
$TimerJobName = "Immediate Alerts"
$webApplicationUrl = "https://mywebappurl/";
 
#custom date range
#$StartTime = "09/26/2015 01:00:00 AM"  # mm/dd/yyyy hh:mm:ss
#$EndTime = "09/26/2015 01:30:00 AM"
 
#yesterday
#$StartTime = (Get-Date).AddDays(-1).ToString('MM-dd-yyyy') + " 00:00:00"
#$EndTime   = (Get-Date).AddDays(-1).ToString('MM-dd-yyyy') + " 23:59:59"
 
#Today
$StartTime = (Get-Date).ToString('MM-dd-yyyy') + " 00:00:00"
$EndTime   = (Get-Date).ToString('MM-dd-yyyy') + " 23:59:59"
 
#Get the specific Timer job for web application
$Timerjob = Get-SPTimerJob | where { $_.DisplayName -eq $TimerJobName -and $_.WebApplication.Url -match $webApplicationUrl }
 
$Timerjob
 
#Get all timer job history from the web application
$Results = $Timerjob.HistoryEntries  |
      where { ($_.StartTime -ge  $StartTime) -and ($_.EndTime -le $EndTime) } |
          Select WebApplicationName,ServerName,Status,StartTime,EndTime, ErrorMessage
 
$Results | Out-GridView