0

I am trying to disable a Runbook schedule using .NET SDK Retrieved the JobScheduled i want to disable and tried setting the associated runbook and schedule to null and "".

                    var schedulenm = new ScheduleAssociationProperty();
                    schedulenm.Name = "";
                    var runbooknm = new RunbookAssociationProperty();
                    runbooknm.Name = "";
                    jocsched.Properties.Schedule = schedulenm;
                    jobsched.Properties.Runbook = runbooknm;

Also tried directly querying the main schedule and set the IsEnabled property to false. However that also doesnt have any impact.

What is the correct way to disable the schedule associated with a runbook? ( just want it disabled not deleted)

Sumesh
  • 123
  • 2
  • 13

1 Answers1

1

According to your description, if you want to disable the schedule associated with a runbook. You could use AutomationManagementClient.JobSchedules.Delete method.

The JobSchedules means the relationship between the runbook and schedule.

After calling this method, the runbook will not associate with schedule, but it will not delete the schedule.

More details, you could refer to below code sample:

     var r2 =  automationManagementClient.JobSchedules.List("groupname", "accountname").JobSchedules.First();


        automationManagementClient.JobSchedules.Delete("groupname", "accountname", r2.Properties.Id);

Result:

You could see the schedule still existed.

Image1:

enter image description here

Image2:

enter image description here

Would that be the exact equivalent of setting the 'Enabled' property to No in the UI?

No, if you want to disable the schedule, you should use AutomationManagementClient.Schedules.Patch method.

More details, you could refer to this codes:

        AutomationManagementClient automationManagementClient = new AutomationManagementClient(aadTokenCredentials, resourceManagerUri);


        SchedulePatchParameters p1 = new SchedulePatchParameters("yourSchedulename");


        SchedulePatchProperties p2 = new SchedulePatchProperties();


        p2.IsEnabled = false;

        p1.Properties = p2;

        var result = automationManagementClient.Schedules.Patch("rgname", "am accountname", p1).StatusCode;

Result: enter image description here

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
  • Thank you, Would that be the exact equivalent of setting the 'Enabled' property to No in the UI? My intention is to temporarily disable the scheduled run and enable it back after sometime in an easy manner. – Sumesh Jun 27 '17 at 05:13
  • No, if you want to disable the schedule, you should use AutomationManagementClient.Schedules.Patch method. You could see my update answer. – Brando Zhang Jun 27 '17 at 05:47
  • Thank You so much! That answers my query. – Sumesh Jun 27 '17 at 06:55