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