Script Powershell per la creazione Timer Job SharePoint 2010
# Url
$siteUrl = "##http://webapp1##"
# Nome dell'assembly
$assemblyName = "##AssemblyName##"
# Nome del Job
$jobName = "##JOB_NAME##"
# Classname del timerjob compreso di namespace.
$timerJobClassName = "##JOB_COMPLETE_CLASS_NAME##"
# caricamento assemnbly
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
[void][reflection.assembly]::LoadwithPartialName($assemblyName)
function Run-Init
{
$global:s = Get-SPSite $siteUrl
$global:webApplication = $s.WebApplication
$global:job = $webApplication.JobDefinitions | ? { $_.Name -like $jobName }
}
function Create-NewJob
{
Stop-Service "SPTimerV4"
Start-Service "SPTimerV4"
# Se il Job già esiste lo cancello
if ($global:job) {
Write-Output 'Job già esistente: cancellazione in corso'
$global:job.Delete()
Write-Output 'Cancellazione del job completata'
}
# Creazione oggetto timer job
$global:job = new-object $timerJobClassName -ArgumentList $jobName,$webApplication
# Creazione scheduling
# http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spschedule.aspx
$sched = new-object Microsoft.SharePoint.SPMinuteSchedule
$sched.BeginSecond = 0
$sched.EndSecond = 5
$sched.Interval = 5
# Configurazione
$global:job.Schedule = $sched
Write-Output 'Creazione Timer Job'
$global:job.Update()
Write-Output 'Operazione completata'
}
Run-Init
Create-NewJob