Programmatically get the timer jobs history for a particular service in the SharePoint 2010 farm


 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Administration;

 

namespace GetJobHistory

{

    class Program

    {

        static void Main(string[] args)

        {          

 

            foreach (SPService service in SPFarm.Local.Services)

            {

                if (service.DisplayName == "My Sample Service")

                {

                    Console.WriteLine("Service Name : "+ service.DisplayName);

                    Console.WriteLine("############################################################");

                    foreach (SPJobHistory entry in service.JobHistoryEntries)

                    {

                        Console.WriteLine("Job Definition Title - " + entry.JobDefinitionTitle + " : Status - " + entry.Status + " : Start Time - " + entry.StartTime);

                    }

                    Console.ReadLine();

                }

            }

        }

    }

}  

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now