Use PowerShell to Run a Timer Job for All SharePoint Web Applications

Tags: Administration, PowerShell, SharePoint 2010

I’m working in my virtual SharePoint 2010 environment and I have an alert set up on the built-in “Announcements” list in my default Team Site.  When testing email functionality, it kind of stinks to have to wait 5 minutes for the timer job to run to send out alert notifications, so I was using this PowerShell script to run the timer job:

Start-SPTimerJob job-immediate-alerts

This was working great.  If I changed an announcement and wanted to ensure that I would receive the email alert, I’d just switch over to PowerShell to run that command.  After a few seconds, I’d see the alert notification email pop into Outlook and life was good.

Keep in mind at this point I only had one web application, “SharePoint – 80.”

Moving forward with the build of my virtual environment, I created another web application on port 112, “SharePoint – 112.”  Pretty standard stuff.

A couple of weeks later I wanted to double-check that email was still working, so I added a new announcement to the Announcements list in the top-level web of the only site collection in my “SharePoint – 80” web application.  After running my PowerShell script to run the “Immediate Alerts” timer job (the same script as above), I noticed that I did not receive my alert notification email.

If you’ve ever worked with timer jobs, you know that each timer job exists per web application (see the screenshot below).  I knew that, but I made a very incorrect assumption:  that the script I was running would run the “Immediate Alerts” timer job for all web applications.  This was not the case.


Ok, so I want to be able to run this timer job for all web applications.  How do I do that?  A simple modification to my PowerShell script now allows me to do so.  Here it is:

$alertTimerJobGuids = Get-SPTimerJob | Where-Object{$ -eq "job-immediate-alerts"}
$alertTimerJobGuids | ForEach-Object {Start-SPTimerJob $_.Id}

The first line gets all timer jobs with the name “job-immediate-alerts.”  This is the name SharePoint can see, while we see “Immediate Alerts” within Central Administration.  The second line just loops through those jobs and runs each one individually.

That gave me the solution that I was looking for.  I don’t consider myself a PowerShell guru by any means, but it’s nice to be able to use the get-help command to find what you’re looking for without having to do a ton of extensive online research.  In fact, I initially started down that road, but didn’t find any immediate answers.  This is one of those cases where figuring it out on my own actually saved me time.  Having done so, I figured I’d write about it in the hopes that one day this can help you too.

SharePoint Nerds Unite!