Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/News/Primer: How to Schedule Azure Automation Runbooks to Process Microsoft 365 Data

Primer: How to Schedule Azure Automation Runbooks to Process Microsoft 365 Data

Tony Redmond / 2025-01-23
Primer: How to Schedule Azure Automation Runbooks to Process Microsoft 365 Data
News

Let Azure Automation Execute Runbooks Using an Automation Schedule

After covering the basics of using Azure Automation runbooks to access Microsoft 365 data, the second part of the primer covers how to write data generated by a runbook to a SharePoint Online list. Populating data on an on-demand basis is valuable, but consistent gathering of data for comparison purposes can be so much more valuable. For that to happen, we need Azure Automation to execute the runbook on a schedule.

Runbook Details

The runbook that I have been using is called GetRecentAccounts. Figure 1 shows the runbook properties as viewed through the Azure portal. Essential details here are the name of the automation account associated with the runbook (M365Automation) and the resource group it uses (ExoAutomation).

Properties of an Azure Automation runbook.
Figure 1: Properties of an Azure Automation runbook

Resource groups are containers that Azure uses to hold resources. Resource groups are also used to track consumption, such as the processing performed by services such as Microsoft 365 backup or SharePoint document translation. An automation schedule is a resource, so it’s managed in a resource group. You might be familiar with the Windows Task Scheduler. The automation schedule is a more secure and better solution for running PowerShell scripts.

Creating an Automation Schedule

Two methods exist to create an automation schedule: through the GUI of the Azure portal or PowerShell using cmdlets from the Az.Accounts and Az.Automation modules. Because this discussion is all about PowerShell, we’ll take the latter option. Besides, using PowerShell to manage object often exposes details that are otherwise easily overlooked.

After installing the latest version of the modules from the PowerShell gallery, connect to the Azure account like this:

Connect-AzAccount -TenantId $TenantId -SubscriptionId $SubscriptionId -AccountId Tony.Redmond@office365itpros.com

You’ll need to know identifier for the tenant and Azure subscription and the account you sign in with must be entitled to manage Azure resources. The subscription identifier is listed in the runbook details (Figure 1) and the tenant identifier is easily found by running the Get-MgOrganization cmdlet:

(Get-MgOrganization).Id

After establishing a connection, you can manage the Azure automation resources available to the account. This code shows how to create a new automation schedule to run at 17:30 every weekday. The names of the automation account and resource group are required. This automation schedule doesn’t have an end date. If you want to add an end date, pass a valid date value in the EndTime parameter. More details about creating automation schedules are in the documentation.

# Set up when the new schedule will start (today at 17:30)
$StartTime = (Get-Date "17:30:00")
$ResourceGroup = "ExoAutomation"
$ScheduleName = "WeekDaySchedule"
$AutomationAccountName = "M365Automation"
# Define what days of the week the schedule will run
[System.DayOfWeek[]]$WeekDays = @([System.DayOfWeek]::Monday..[System.DayOfWeek]::Friday)

# Create the new schedule
New-AzAutomationSchedule -AutomationAccountName $AutomationAccountName -Name $ScheduleName -StartTime $StartTime -WeekInterval 1 -DaysOfWeek $WeekDays -ResourceGroupName $ResourceGroup -Description 'Schedule to execute runbooks at 17:30 UTC on weekdays'

# Check its details
Get-AzAutomationSchedule -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccountName

StartTime              : 22/01/2025 17:30:00 +00:00
ExpiryTime             : 31/12/9999 23:59:00 +00:00
IsEnabled              : True
NextRun                : 22/01/2025 17:30:00 +00:00
Interval               : 1
Frequency              : Week
MonthlyScheduleOptions :
WeeklyScheduleOptions  : Microsoft.Azure.Commands.Automation.Model.WeeklyScheduleOptions
TimeZone               : Etc/UTC
ResourceGroupName      : ExoAutomation
AutomationAccountName  : M365Automation
Name                   : WeekDaySchedule
CreationTime           : 22/01/2025 17:12:50 +00:00
LastModifiedTime       : 22/01/2025 17:16:02 +00:00
Description            : Schedule to execute runbooks at 17:30 UTC on weekdays

Register the Runbook with an Automation Schedule

Before Azure Automation can execute a runbook without human intervention, the runbook must be registered with an automation schedule. This code does the job, as does the Link to schedule option shown in Figure 1.

# Name of runbook to schedule
$RunbookName = "GetRecentAccounts"

Register-AzAutomationScheduledRunbook -AutomationAccountName $AutomationAccountName -Name $RunbookName -ScheduleName $ScheduleName -ResourceGroupName $ResourceGroup
Register-AzAutomationScheduledRunbook: The runbook has no published version. Runbook name GetRecentAccounts.

Or rather, it would if the runbook was published. Up to now, the runbook has been under active development, and we’ve used the test pane feature to make sure that the runbook code runs as expected. Eventually, a runbook reaches the point where the code works and is stable. At that point, you should publish the runbook to create a version that Azure Automation can schedule. Development can still continue, but Azure Automation will only run the published version.

To create a published version, edit the runbook and choose the Publish option (Figure 2).

Azure portal option to publish a runbook.Azure automation runbook.
Figure 2: Azure portal option to publish a runbook

Alternatively, use the Publish-AzAutomationRunbook cmdlet to publish the runbook:

$Params = @{}
$Params.Add("Name", $RunbookName)
$Params.Add("ResourceGroupName", $ResourceGroup)
$Params.Add("AutomationAccountName", $AutomationAccountName)
Publish-AzAutomationRunbook @Params

Location              : westeurope
Tags                  : {}
JobCount              : 0
RunbookType           : PowerShell72
Parameters            : {}
LogVerbose            : False
LogProgress           : False
LastModifiedBy        :
State                 : Published
ResourceGroupName     : ExoAutomation
AutomationAccountName : M365Automation
Name                  : GetRecentAccounts
CreationTime          : 20/01/2025 15:03:41 +00:00
LastModifiedTime      : 22/01/2025 18:06:47 +00:00
Description           : Find recently created accounts

Either way, the runbook can now be registered with an automation schedule in the Azure portal or by running the Register-AzAutomationScheduledRunbook cmdlet. Confirmation of the scheduling can be obtained by examining the details of the schedule in the Azure portal (Figure 3) or by running the Get-AzAutomationScheduledRunbook cmdlet:

Get-AzAutomationScheduledRunbook -RunbookName $RunbookName -ScheduleName $ScheduleName -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccountName

ResourceGroupName     : ExoAutomation
RunOn                 :
AutomationAccountName : M365Automation
JobScheduleId         : 9a2aadd0-c3ac-4baa-8cfb-855b12a1a277
RunbookName           : GetRecentAccounts
ScheduleName          : WeekDaySchedule
Confirming that a runbook is registered with an automation schedule.
Figure 3: Confirming that a runbook is registered with an automation schedule

To confirm that everything’s running as expected, wait until after the job should run and check the output location for new data or use the Get-AzAutomationJob cmdlet:

Get-AzAutomationJob -ResourceGroupName $ResourceGroup -RunbookName $RunbookName -AutomationAccountName $AutomationAccountName | Where-Object {$_.Status -eq 'Completed'} | Format-Table StartTime, EndTime, RunbookName, Status

StartTime                  EndTime                    RunbookName       Status
---------                  -------                    -----------       ------
22/01/2025 17:30:59 +00:00 22/01/2025 17:31:53 +00:00 GetRecentAccounts Completed

The Value of Scheduled Runbooks

There’s nothing like an automated schedule to make sure that jobs get run at the right time. The combination of runbooks and schedules means that you can be sure that important Microsoft 365 automation processes are executed. That’s a nice feeling.


Need some assistance to write and manage PowerShell scripts for Microsoft 365? Get a copy of the Automating Microsoft 365 with PowerShell eBook, available standalone or as part of the Office 365 for IT Pros eBook bundle.

 

Share this!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss