Note: Be sure to change the Target Framework of the project to .NET Framework 3.5.
using System;
using System.Linq;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace DisableTimerJobs
{
class Program
{
static void Main(string[] args)
{
try
{
SPFarm farm = SPFarm.Local;
//Get all SharePoint Web services
SPWebService service = farm.Services.GetValue<SPWebService>("");
int Count = 0;
foreach (SPWebApplication webapp in service.WebApplications)
{
foreach (SPJobDefinition job in webapp.JobDefinitions)
{
//this example is to run on one service only
//if (job.Name == "SchedulingNotification")
//{
Count++;
try
{
//disable all jobs
job.IsDisabled = true;
job.Update();
Console.WriteLine(Count + ") " + job.Name + ": ");
if (job.IsDisabled == true)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Disabled");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Enabled");
Console.ResetColor();
}
}
catch (Exception ex)
{
Console.WriteLine(Count + ") " + job.Name + ": ");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ERROR: ");
Console.WriteLine(ex.ToString());
Console.ResetColor();
Console.ReadLine();
}
//}
}
}
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("ERROR: ");
Console.WriteLine("An error has occured: ");
Console.WriteLine(ex.ToString());
Console.ResetColor();
Console.ReadLine();
}
Console.WriteLine("Done. Press enter to exit.");
Console.ReadLine();
}
}
}
