Create a schedule for a runbook in automation with C#

Copper Contributor

So, I have been struggling with this for a while now, but I am getting a bit further each day. But now I am really stuck.

 

What I am trying to do:

  • I have an automation account with a runbook (PowerShell)
  • I want to create a schedule
  • Then I want to connect that schedule to the runbook so the runbook is executed at a specific date and time.

I want to achieve this through C# with the Management API of Azure. I found a few webpages that should give me all the information I needed, but it doesn't work.

The first one is this: https://learn.microsoft.com/en-us/rest/api/automation/schedule/create-or-update?tabs=HTTP

I get this to work and I can see the schedule after I ran the code.

 

The second one is this: https://learn.microsoft.com/en-us/rest/api/automation/job-schedule/create?tabs=HTTP
And here I get stuck. I get a 404 error when I execute the request and I have no idea what I am doing wrong.

 

I have attached a test project that has everything I need to create the schedule and connect it to the runbook. It works with .NET 7 and uses unit tests to execute the logic.

Just note that the code isn't perfect. I just want to make it work first before refactoring it.

 

Also, in the file ScheduleLogic.cs are some properties you might want to fill before you start it. I removed the values due to privacy and stuff.

 

I have the feeling I am almost there, but that I just made a stupid mistake which I can't find.

 

Thank you

0 Replies