2

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.

2
  • do you want to edit the timerjob to change the schedual sharepoint.stackexchange.com/questions/116418/… Commented Nov 26, 2015 at 8:25
  • No, i only want to change this competitorSyncJob.Properties.Add(Const.TIMERJOBS_COMPSYNC_JOB_NAME, "sp2013/sites/mysite"); (the URL) afterwards Commented Nov 26, 2015 at 8:26

1 Answer 1

2

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!!

1
  • normally so simple :) Commented Nov 26, 2015 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.