Azure Automation – What Is It and What Is It Used For?

5.8.2025 | Autor: Martin Hasin
8

Azure Automation is a cloud service from Microsoft that allows you to automate repetitive tasks both within and outside of Azure. It is primarily used to manage and orchestrate tasks using PowerShell scripts, Python scripts, or visual workflows (Runbooks).

Azure Automation – What Is It and What Is It Used For?

Azure Automation – What is it and what is it used for?Key features of Azure Automation:

  1. Runbooks – Enable you to automate tasks in and outside of Azure.
  2. Scheduled Jobs – Schedule tasks to run automatically at specific times.
  3. Hybrid Runbook Worker – Run scripts on on-premises servers.
  4. Update Management – Automate updates for Windows/Linux VMs.
  5. Change Tracking – Monitor configuration changes in systems.
  6. State Configuration (DSC) – Automate infrastructure configuration using PowerShell DSC.

How to automate scripts in Azure Automation?

Azure Automation allows you to run scripts using Runbooks, which can be:

  • PowerShell (.ps1)
  • Python (.py)
  • Visual workflows (drag & drop)

1. Creating a PowerShell Runbook in the Azure Portal

1.1 Creating an Automation Account

  1. In the Azure Portal → Automation Accounts → Create.
  2. Enter a name and Resource Group.
  3. Click Create.

1.2 Creating a Credential

To use a Service Principal or other credentials in a Runbook, you must store them as a Credential Asset in Azure Automation.

Procedure:

  1. In the Azure Portal → Open the Automation Account.
  2. In the left menu, select Credentials.
  3. Click Add a credential.
  4. Fill in:
    • Name: ServicePrincipal
    • User Name: client_id (from App Registration in Azure AD)
    • Password: client_secret
  5. Click Create.

1.3 Creating a Runbook

  1. In your Automation Account, go to Runbooks → Create a Runbook.
  2. Select PowerShell as the type and enter a name, e.g., Refresh-Model.ps1.
  3. Paste the code, e.g.:
param
(
    [Parameter (Mandatory = $false)]
    [object] $WebhookData,
[Parameter (Mandatory = $false)]
    [String] $DatabaseName,
    [Parameter (Mandatory = $false)]
    [String] $AnalysisServer,
    [Parameter (Mandatory = $false)]
    [String] $RefreshType
)
$_Credential = Get-AutomationPSCredential -Name "ServicePrincipal"
# If the runbook was called from a Webhook, WebhookData will not be null.
if ($WebhookData)
{
    # Retrieve AAS details from the Webhook request body

$atmParameters = (ConvertFrom-Json -InputObject $WebhookData.RequestBody)

    Write-Output "CredentialName: $($atmParameters.CredentialName)"
    Write-Output "AnalysisServicesDatabaseName: $($atmParameters.AnalysisServicesDatabaseName)"
Write-Output "AnalysisServicesServer: $($atmParameters.AnalysisServicesServer)"
    Write-Output "DatabaseRefreshType: $($atmParameters.DatabaseRefreshType)"    
    $_databaseName = $atmParameters.AnalysisServicesDatabaseName
    $_analysisServer = $atmParameters.AnalysisServicesServer
$_refreshType = $atmParameters.DatabaseRefreshType 
    Invoke-ProcessASDatabase -DatabaseName $_databaseName -RefreshType $_refreshType -Server $_analysisServer -ServicePrincipal -Credential $_credential
}
else
{
    Invoke-ProcessASDatabase -DatabaseName $DatabaseName -RefreshType $RefreshType -Server $AnalysisServer -ServicePrincipal -Credential $_Credential
}

4. Click Publish.

2. Scheduling Automatic Execution

After creating a Runbook, you can set it to run automatically.

  1. Go to Runbook → Schedules → Add a Schedule.
  2. Set it to run every day at 3:00 AM.
  3. Add parameters (e.g., database name).



For more technical articles, guides, and interesting IT topics, visit: www.virtualall.sk


Martin Hasin

Martin Hasin

An expert in cybersecurity, Azure Cloud management, and on-premises VMware. He uses technologies such as Checkmk and MRTG to monitor networks and improve the efficiency and security of IT infrastructure.