SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Powershell Script -- Start Custom Timer Job Out of Schedule

I find it sometimes that I need to start one of my custom timer jobs ahead of schedule (normally for testing purpose) so I decided to put together a Powershell that calls the execute method of the SPJobDefintion.

OneTimeJob.ps1 

param
(
 [string] $jobName
)

[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")

$service = [Microsoft.SharePoint.Administration.SPWebService]::AdministrationService
$webApps = $service.WebApplications

foreach ($webApp in $service.WebApplications)
{
     $job = $webApp.JobDefinitions | where { $_.Name -eq $jobName } 

     if ($job -ne $NULL)
     {
           $job.Execute([system.guid]::Empty)
           Write "Job Executed"
     }
     else
     {
           Write "Job Not Found"
     }
}

# END SCRIPT

To run, pass in the name of the time job class.

 \OneTimeJob.ps1 "TeamEli.SharePoint.OneTimer"

 Hope this saves somebody some time.

Eli


Posted 10-02-2008 11:06 PM by undercoverlaptop

Comments

William Powell wrote re: Powershell Script -- Start Custom Timer Job Out of Schedule
on 10-03-2008 12:34 PM

Extremely useful.

Thanks for sharing!

Links (10/5/2008) « Steve Pietrek - Everything SharePoint wrote Links (10/5/2008) « Steve Pietrek - Everything SharePoint
on 10-05-2008 7:08 PM

Pingback from  Links (10/5/2008) « Steve Pietrek - Everything SharePoint

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.