Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

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.