I'm following this http://msdn.microsoft.com/en-us/library/cc406686%28office.12%29.aspx and have successfully created a TimerJob that is WebApplication wide.

this line

foreach (SPSite siteCollection in this.WebApplication.Sites) 

appears that sometimes, its enumerating all the sites except the Central Administration...do I need to change it to be scoped to the farm level?

or I guess at better question is...'how do I enumerate every site in a farm?'

1 Answer 1


SPJobDefinition has two constructors

One for web applications:


And one for services:


You can attach to the central admin service (like the Health Analysis Job)

Or the Microsoft SharePoint Foundation Timer service (check http://bnedgsp06:8080/_admin/ServiceJobDefinitions.aspx) as it has most of the inbuilt timer jobs

A good example of a farm wide job is: Microsoft.Office.Server.UserProfiles.WSSProfileSyncJob

which has an Execute like this:

public override void Execute()
    foreach (SPWebApplication application in SPFarm.Local.Services.GetValue<SPWebService>(string.Empty).WebApplications)
        if (base.JobState.ShouldStop)
        if (!UserProfileServiceProxy.ServiceProxy.ExcludedWebApplications.Contains(application.Id))
//do stuff

You can find other global job definitions type names using this powershell:

((get-spfarm).Services |? {$_.TypeName -eq "Microsoft SharePoint Foundation Timer"}).JobDefinitions | select TypeName
  • Thanks djeeg. So to enumerate every site, this would be the code 'foreach (SPWebApplication application in SPFarm.Local.Services.GetValue<SPWebService>(string.Empty).WebApplications) { foreach (SPSite site in application.Sites) {'
    – Iunknown
    Apr 11, 2011 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.