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:
Log onto a VM.
Open PowerShell.
Execute a script.
Create/update some files.
Check whether the operation worked.
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:
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:
After it is created, let us run the PS command. For that you need to create a Runbook.
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
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 $fileSave and Publish it and then click on Start. It will create a job and you can see under the Jobs in Resources blade.
For recurring jobs, you need to create a schedule and then link it to the Runbook





