I created this particular command because I needed to get some additional information about service level timer jobs. If you go to Central Admin -> Operations -> Time Job Definitions (or status) you’ll see all the timer jobs for the farm. This includes those associated with a particular web application and a service. I already had a command to get all the jobs for a web app (GetJobInfos) however this command didn’t give me all the information I was looking for (and I did not author this command so I wanted to keep changes to it minimal though in the end I did end up having to modify it slightly).

So this command, gl-enumtimerjobdefinitions, won’t be entirely useful to most people – I’m just outputting more information than the other and the results are in XML rather than flat text (I suppose if someone wanted to consume the XML output then you could do other programmatic things with that).

The code for this is pretty simplistic. I’ve got two primary methods which take care of adding either a service’s jobs or a web app’s jobs and then a third which determines which of the other two should be called. There’s also a fourth method which just takes a job and produces the XML nodes for that job. The core code is shown below:

 1/// Adds the service.
 2/// 
 3/// The service.
 4/// The XML doc.
 5private static void AddService(SPService service, XmlDocument xmlDoc)
 6{
 7    SPWebService service2;
 8 
 9    foreach (SPJobDefinition job in service.JobDefinitions)
10    {
11        Helper.GetJobInformation(job, xmlDoc);
12    }
13    service2 = service as SPWebService;
14    if (service2 == null)
15    {
16        return;
17    }
18    foreach (SPWebApplication application in service2.WebApplications)
19    {
20        AddWebApplication(application, xmlDoc);
21    }
22}
23 
24/// 
25/// Adds the web application.
26/// 
27/// The webapp.
28/// The XML doc.
29private static void AddWebApplication(SPWebApplication webapp, XmlDocument xmlDoc)
30{
31    foreach (SPJobDefinition job in webapp.JobDefinitions)
32    {
33        Helper.GetJobInformation(job, xmlDoc);
34    }
35}
36 
37 
38/// 
39/// Builds the XML doc.
40/// 
41/// The mode.
42/// The service.
43/// The web app.
44public static XmlDocument BuildXmlDoc(JobSelectionMode mode, SPService service, SPWebApplication webApp)
45{
46    XmlDocument xmlDoc = new XmlDocument();
47    xmlDoc.AppendChild(xmlDoc.CreateElement("Jobs"));
48 
49    switch (mode)
50    {
51        case JobSelectionMode.Farm:
52            foreach (SPService temp in SPFarm.Local.Services)
53            {
54                AddService(temp, xmlDoc);
55            }
56            break;
57        case JobSelectionMode.Service:
58            if (service == null)
59            {
60                break;
61            }
62            AddService(service, xmlDoc);
63            break;
64        case JobSelectionMode.WebApplication:
65            if (webApp != null)
66            {
67                AddWebApplication(webApp, xmlDoc);
68            }
69            break;
70    }
71    return xmlDoc;
72}

The syntax of the command can be seen below:

C:\>stsadm -help gl-enumtimerjobdefinitions

stsadm -o gl-enumtimerjobdefinitions

Displays Information about the all Timer Jobs for the Farm, Service, or Web Application.

Parameters:
        [-scope <Farm (default) | Service | WebApplication>]
        [-serviceid <ID of the service if Service is specified for scope>]
        [-webappurl <URL of the web application if WebApplication is specified for scope>]

Here’s an example of how to return the timer jobs for the entire farm:

stsadm –o gl-enumtimerjobdefinitions

The results of running the above command are rather lengthy so I’ll only show what one particular job looks like:

 1<Jobs>
 2    <Job Id="5e8eadcc-95f7-4a36-acf5-e30641d15d63" Title="Workflow Failover" Name="job-workflow-failover">
 3        <Service>
 4            <Name></Name>
 5            <Id>d8952551-e4a4-4b0f-b2d9-5a1fce3de025</Id>
 6            <DisplayName></DisplayName>
 7            <TypeName>Windows SharePoint Services Web Application</TypeName>
 8        </Service>
 9        <WebApplication>
10            <Name>Blogs - 80</Name>
11            <Id>527ebc95-750b-45e2-995b-001aaaf9636c</Id>
12        </WebApplication>
13        <DisplayName>job-workflow-failover</DisplayName>
14        <IsDisabled>False</IsDisabled>
15        <LastRunTime>9/7/2007 4:15:40 PM</LastRunTime>
16        <LockType>ContentDatabase</LockType>
17        <Retry>False</Retry>
18        <Status>Online</Status>
19        <TypeName>Microsoft.SharePoint.Administration.SPWorkflowFailOverJobDefinition</TypeName>
20        <Version>5548</Version>
21        <ScheduleTypeName>Microsoft.SharePoint.SPMinuteSchedule</ScheduleTypeName>
22        <NextOccurrenceBasedOnNow>9/7/2007 4:45:42 PM</NextOccurrenceBasedOnNow>
23        <Schedule>
24            <BeginSecond>0</BeginSecond>
25            <EndSecond>59</EndSecond>
26            <Interval>15</Interval>
27        </Schedule>
28    </Job>
29</Jobs>