Failed timer jobs via powershell

Hi Friends,

Is it possible to get an output of the failed timer jobs in the Central Admin via powershell? If yes, could anybody please share the script?

November 14th, 2012 12:09pm

Is this what you're after? It lists all the timer jobs that haven't succeeded for a webapplication

$wa = Get-SPWebApplication http://mywebapp
$wa.JobHistoryEntries | ?{$_.Status -ne "Succeeded"} | Ft JobDefinitionTitle,Status

Free Windows Admin Tool Kit Click here and download it now
November 14th, 2012 12:22pm

Did it help, or were you looking for something different?
November 15th, 2012 10:18am

Hi Matthew,

The script that you have provided is for a webapplication, but in the Central administration, we can find the failed timer job definitions for the entire farm where we cannot filter down by the web application.

Free Windows Admin Tool Kit Click here and download it now
November 19th, 2012 12:54pm

How about this then ;-)

$f = get-spfarm
$ts = $f.TimerService
#Display all jobs that haven't succeeded (I.e. Paused)
$ts.JobHistoryEntries | ?{$_.Status -ne "Succeeded"} | Ft JobDefinitionTitle,Status
#Display only failed jobs
$ts.JobHistoryEntries | ?{$_.Status -eq "Failed"} | Ft JobDefinitionTitle,Status
#Display more information
$ts.JobHistoryEntries | ?{$_.Status -eq "Failed"} | fl

November 19th, 2012 1:14pm

Great script!! It works...  Now that it is working, is it possible to include a timestamp like for the past 1 week and also if the output is exactly as below it would be great!!

Free Windows Admin Tool Kit Click here and download it now
November 19th, 2012 2:59pm

Everything is possible with PowerShell ;-)

$f = get-spfarm
$ts = $f.TimerService
$ts.JobHistoryEntries | ?{$_.Status -eq "Failed" -and $_.StartTime -gt ((get-date).AddDays(-7))} | Ft JobDefinitionTitle,Status,StartTime,EndTime,@{Label="TotalRunningTime"; Expression={$_.EndTime - $_.StartTime}}

November 19th, 2012 3:59pm

Thanks for the script Matthew, its working fine.. the requirement is inclusive of the below column names, which I am not able to get and in order:

JobDefinitionTitle,Server, web application, duration, Status,StartTime,EndTime

Getting this output in a CSV or XLS would help a great deal.

Free Windows Admin Tool Kit Click here and download it now
November 20th, 2012 8:11am

Hey Shonilchi,

I've uploaded a script to the Technet Gallery that exports the information to a CSV file. The WebApplication appears to always be empty in the history list, so I've omittd it from the script).

The link to it is here: http://gallery.technet.microsoft.com/sharepoint/Export-Failed-Timer-Jobs-ee69a53d

Hope it helps, Matt

November 21st, 2012 9:09pm

Thanks a lot Matthew!! ;)  It really helped..
Free Windows Admin Tool Kit Click here and download it now
November 26th, 2012 12:12pm

Superb matthew, :) Can i get a script to get a list of all timer jobs with the schedule, please let me know.
July 8th, 2013 11:35am

Hi SenjiVi,

You can get a collection of all the timer jobs running on the farm and webapplications like this;

$items = New-Object psobject 
$items | Add-Member -MemberType NoteProperty -Name "Title" -value "" ;
$items | Add-Member -MemberType NoteProperty -Name "Schedule" -value "" ;
$items | Add-Member -MemberType NoteProperty -Name "WebApplication" -value "" ;

$webapplications = Get-SPWebApplication
$jobCollection = @();
foreach($wa in $webapplications)
{
$jd = $wa.JobDefinitions;
foreach($job in $jd)
{
$j = $items | Select-Object *; 
$j.Title=$job.Title; 
$j.WebApplication=$job.WebApplication.Url; 
$j.Schedule=$job.Schedule; 
$jobCollection += $j
}
}

#Add the farm jobs
$f = get-spfarm
$ts = $f.TimerService
$jd = $ts.JobDefinitions
foreach($job in $jd)
{
$j = $items | Select-Object *; 
$j.Title=$job.Title; 
$j.WebApplication="Farm"; 
$j.Schedule=$job.Schedule; 
$jobCollection += $j
}

The script defines a new object for storing job information. It then parses all the jobs in all webapplications, adding each SPTimerJob to a new object, adding each object to the collection of jobs. Once this has finished, you have a collection of "jobs" that you can filter or sort like any other PowerShell collection.

$jobCollection | FT
#Or
$jobCollection | ?{$_.Webapplication -like "http://devmy101*"} | FT Title,Schedule,Webapplication -AutoSize

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2013 10:07am

Hi Matthew,

I tried the above script; it just runs, meaning, am not getting an output.. Please help.. I require this in a CSV or XML.

July 29th, 2013 3:08pm

This script just runs, doesnot provide any output. can you please help

Free Windows Admin Tool Kit Click here and download it now
August 6th, 2013 12:18pm

Finally got it working.  Here is the script:

$items = New-Object psobject 
$items | Add-Member -MemberType NoteProperty -Name "Title" -value "" ;
$items | Add-Member -MemberType NoteProperty -Name "Schedule" -value "" ;
$items | Add-Member -MemberType NoteProperty -Name "WebApplication" -value "" ;

$webapplications = Get-SPWebApplication
$jobCollection = @();
foreach($wa in $webapplications)
{
$jd = $wa.JobDefinitions;
foreach($job in $jd)
{
$j = $items | Select-Object *; 
$j.Title=$job.Title; 
$j.WebApplication=$job.WebApplication.Url; 
$j.Schedule=$job.Schedule; 
$jobCollection += $j
}
}

#Add the farm jobs
$f = get-spfarm
$ts = $f.TimerService
$jd = $ts.JobDefinitions
foreach($job in $jd)
{
$j = $items | Select-Object *; 
$j.Title=$job.Title; 
$j.WebApplication="Farm"; 
$j.Schedule=$job.Schedule; 
$jobCollection += $j
}

$jobCollection | ?{$_.Webapplication -like "Your site URL*"} | Format-List Title,Schedule,Webapplication > c:\jobs.txt

August 6th, 2013 12:25pm

Hi Shonilchi, 

You haven't actually changed the script, other than to pipe the output of Format-Table to a text file. 

The script (that I posted above) creates a collection of "jobs", which are stored in the $jobCollection variable. 

The original code I posted above contained an example that filtered the collection based on a webapplication URL (which was http://devmy101), and then displayed the results using Format-Table.

To create a CSV report using this collection, you would send the $jobCollection variable to the Export-CSV PowerShell cmdlet, like this:

$jobCollection | Export-Csv -Path C:\temp\jobsreport.csv -NoTypeInformation

If you wanted to create a CSV report of all the jobs that had failed on the farm, then this would be the complete code:

$items = New-Object psobject 
$items | Add-Member -MemberType NoteProperty -Name "Title" -value "" ;
$items | Add-Member -MemberType NoteProperty -Name "Schedule" -value "" ;
$items | Add-Member -MemberType NoteProperty -Name "WebApplication" -value "" ;

$webapplications = Get-SPWebApplication
$jobCollection = @();
foreach($wa in $webapplications)
{
$jd = $wa.JobDefinitions;
foreach($job in $jd)
{
$j = $items | Select-Object *; 
$j.Title=$job.Title; 
$j.WebApplication=$job.WebApplication.Url; 
$j.Schedule=$job.Schedule; 
$jobCollection += $j
}
}

#Add the farm jobs
$f = get-spfarm
$ts = $f.TimerService
$jd = $ts.JobDefinitions
foreach($job in $jd)
{
$j = $items | Select-Object *; 
$j.Title=$job.Title; 
$j.WebApplication="Farm"; 
$j.Schedule=$job.Schedule; 
$jobCollection += $j
}

#Create the report and save it as jobsreport.csv in the C:\temp directory
$jobCollection | Export-Csv -Path C:\temp\jobsreport.csv -NoTypeInformation

Free Windows Admin Tool Kit Click here and download it now
August 6th, 2013 12:40pm

Hi,

I am trying to do the same for Content Deployment jobs. How to pull the failed jobs info for CD's.

Thanks,

Raj.

November 21st, 2013 12:40am

This particular thread posting you led with the comment:

> If you wanted to create a CSV report of all the jobs that had failed on the farm, then this would be the complete code:

I don't see anything in this code that selects from the list of all timer jobs just the ones that failed.

I presume this means that I misunderstand the code, since the code that is listed as the "complete" code appears, to me, to be the same as the earlier code that was posted to list all jobs on the farm.

Am I missing something obvious?

Free Windows Admin Tool Kit Click here and download it now
April 25th, 2014 2:00pm

Awesome script ...

Please check below link

http://parmeshwarjadhao.blogspot.in/2015/02/powershell-script-for-daily-failed-job.html

March 25th, 2015 2:54am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics