SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm following this 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 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?'

share|improve this question
up vote 7 down vote accepted

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
share|improve this answer
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 '11 at 14:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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