Domanda

I am currently adding a Property to my Timerjob in FeatureActivated via C#. This is my code.

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWebApplication wa = properties.Feature.Parent as SPWebApplication;

        foreach (SPJobDefinition job in wa.JobDefinitions)
        {
            if (job.Name == Const.TIMERJOBS_COMPSYNC_JOB_NAME)
                job.Delete();
        }

        Core.Timerjobs.CompetitorSyncJob competitorSyncJob = new Core.Timerjobs.CompetitorSyncJob(Const.TIMERJOBS_COMPSYNC_JOB_NAME, wa);

        SPHourlySchedule schedule = new SPHourlySchedule();
        schedule.BeginMinute = 0;
        schedule.EndMinute = 59;

        competitorSyncJob.Schedule = schedule;
        competitorSyncJob.Properties.Add(Const.TIMERJOBS_COMPSYNC_JOB_NAME, "http://sp2013/sites/mysite");
        competitorSyncJob.Update();
    }

I couldnt find a way to do this via Powershell. I have to do this to be able to change settings between development, staging and production.

È stato utile?

Soluzione

In PowerShell you have to access the Timer Job object and set the property of it.

You can try following cmdlets.

$tj = Get-SPTimerJob -WebApplication [WebApplication] | where {$_.Name -eq "[TimerJobName]"}
$tj.Properties.Add("key","val")
$tj.Update()

Here in [TimerJobName] you have to pass the timer job name or if you have title then you can place where {$_.Title -eq "[TimerJobTitle]"} condition.

After getting the timer job object you can set it's property as it is shown in the above cmdlet.

Hope this helps!!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top