in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Team Eli's blog

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

Comments

 

William Powell said:

Extremely useful.

Thanks for sharing!

October 3, 2008 12:34 PM
 

Links (10/5/2008) « Steve Pietrek - Everything SharePoint said:

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

October 5, 2008 7:08 PM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts