Thursday, September 24, 2026

Azure Automation - Schedule Jobs on VM

 

Overview

Azure Automation is a cloud-based automation service that allows operational and administrative tasks to be executed automatically rather than relying on someone to manually log onto a server and perform them.

Typical examples include:

  • Running PowerShell scripts

  • Performing routine maintenance tasks

  • Creating or updating files

  • Calling internal APIs

  • Performing health checks

  • Automating repetitive operational procedures

  • Running tasks on a schedule

One particularly useful capability is the Hybrid Runbook Worker.

A Hybrid Runbook Worker allows an Azure Automation runbook to execute directly on an Azure VM, giving the script access to the VM's local resources and resources accessible from the VM's network. Microsoft describes Hybrid Runbook Workers as a mechanism for executing runbooks directly on the worker machine and against resources in its local environment.


1. Why use Azure Automation?

Consider a simple operational procedure:

  1. Log onto a VM.

  2. Open PowerShell.

  3. Execute a script.

  4. Create/update some files.

  5. Check whether the operation worked.

  6. Repeat the same process tomorrow.

This works but requires human intervention every time. To overcome this, we can leverage Azure Automation → Runbook.

Go to Automation Accounts in azure Portal and create an Automation Account:

 

image-20260925-044401.png

 

image-20260925-044137.png

Go to TDEAutomates → Hybrid worker groups. This is where you connect your VM to your worker job

Here create a work and select your VM:

image-20260925-044629.png

 


After it is created, let us run the PS command. For that you need to create a Runbook.

image-20260925-044954.png

Chose Powershell from Runbook Type and a suitable PS version (5.1)

Now we need to write the Powershell inside runbook. Go inside runbook created and Edit in Portal

image-20260925-045209.png

I have used the below Powershell to create a file in C:\Temp folder in VM

Write-Output "===== Azure Automation Test =====" $folder = "C:\Temp" $file = "C:\Temp\AzureAutomationTest.txt" Write-Output "Running on computer: $env:COMPUTERNAME" Write-Output "Running as: $(whoami)" # Create C:\Temp if it doesn't exist if (-not (Test-Path $folder)) { New-Item -Path $folder -ItemType Directory -Force } # Create the test file "Hello from Azure Automation" | Set-Content -Path $file Write-Output "File created successfully:" Write-Output $file

Save and Publish it and then click on Start. It will create a job and you can see under the Jobs in Resources blade.

image-20260925-045450.png

For recurring jobs, you need to create a schedule and then link it to the Runbook