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?
Technology Tips and News
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?
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
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.
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
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!!
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}}
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.
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
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
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.
This script just runs, doesnot provide any output. can you please help
Finally got it working. Here is the script:
$items = New-Object psobjectHi 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
Hi,
I am trying to do the same for Content Deployment jobs. How to pull the failed jobs info for CD's.
Thanks,
Raj.
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?
Awesome script ...
Please check below link
http://parmeshwarjadhao.blogspot.in/2015/02/powershell-script-for-daily-failed-job.html