You are here: Home » Powershell Script — Start Custom Timer Job Out of Schedule

Powershell Script — Start Custom Timer Job Out of Schedule

Posted by undercoverlaptop
1 Comment »

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

1 Comment

Your email is never shared.
Required fields are marked *




Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>