Prerequisites

Before we get started, ensure you have the following:

  • An active Azure subscription
  • Azure CLI installed on your computer

Step 1: Create an Automation Account

  1. Open the Azure Portal and navigate to the Automation Accounts page.
  2. Click on the +Add button and enter the required details, such as the name, subscription, resource group, and region.
  3. Choose a pricing tier based on your requirements, such as Free or Basic.
  4. Click on Review + create and then Create to create the automation account.

Step 2: Create a Runbook

  1. Navigate to the Automation Account that you just created.
  2. Click on Runbooks and then on the +Add button to create a new runbook.
  3. Choose a name and a runbook type, such as PowerShell or Python.
  4. Write your script in the editor or upload an existing script.
  5. Click on Save to save your runbook.

Step 3: Test the Runbook

  1. Click on the Test pane to test your runbook.
  2. Select a test job and then click on Start to run the job.
  3. Monitor the job status and output to ensure that your runbook is working correctly.

Step 4: Schedule the Runbook

  1. Click on the Schedule pane to schedule your runbook.
  2. Choose a schedule type, such as a recurring schedule or a one-time schedule.
  3. Set the schedule details, such as the start time, end time, and time zone.
  4. Click on Create to create the schedule for your runbook.

Step 5: Monitor the Runbook

  1. Click on the Jobs pane to monitor your runbook.
  2. View the job status, output, and logs for each job.
  3. Use filters and sorting to find specific jobs or analyze job trends.
  4. Click on a job to view more details about the job, such as the input, output, and runtime.

Using Azure CLI Commands

Here are some Azure CLI commands that you can use for Azure Automation:

  • To create an Automation Account:
az automation account create --name <account_name> --resource-group <resource_group_name> --location <location> --sku <sku_name>

To create a Runbook:

az automation runbook create --account-name <account_name> --resource-group <resource_group_name> --name <runbook_name> --type <runbook_type>

To update a Runbook:

az automation runbook update --account-name <account_name> --resource-group <resource_group_name> --name <runbook_name> --type <runbook_type> --publish

To start a Runbook:

az automation job create --account-name <account_name> --resource-group <resource_group_name> --runbook-name <runbook_name> --parameters <parameters>

To schedule a Runbook:

az automation schedule create --account-name <account_name> --resource-group <resource_group_name> --schedule-name <schedule_name> --start-time <start_time> --timezone <timezone> --frequency <frequency> --interval <interval>

To monitor a Runbook:

az automation job list --account-name <account_name> --resource-group <resource_group_name> --runbook-name <runbook_name> --top <top> --orderby <orderby>

These are just a few examples of the many Azure CLI commands available for Azure Automation. You can find more information on the Azure CLI documentation page.

I hope this tutorial helps you get started with Azure Automation and CLI commands. If you have any further questions or require additional assistance, feel free to ask!

Step 6: Create a Hybrid Runbook Worker

Sometimes, you may need to run automation tasks on machines that are not connected to Azure, such as on-premises servers. In this case, you can use a Hybrid Runbook Worker to run your runbooks on those machines.

Here are the steps to create a Hybrid Runbook Worker:

  1. Download and install the Hybrid Runbook Worker software on the machine you want to use.
  2. Open the Azure Portal and navigate to the Automation Account.
  3. Click on Hybrid Worker Groups and then on the +Add button to create a new group.
  4. Choose a name for the group and then click on Create to create the group.
  5. Click on the new group to open it and then click on the +Add button to add a new worker.
  6. Choose a name for the worker and then enter the connection information, such as the group name, group key, and registration key.
  7. Click on Save to save the worker.

Step 7: Create a Hybrid Runbook

Once you have a Hybrid Runbook Worker set up, you can create Hybrid Runbooks to run on those machines. Here are the steps to create a Hybrid Runbook:

  1. Navigate to the Runbooks page in the Automation Account.
  2. Click on the +Add button to create a new runbook.
  3. Choose a name for the runbook and then choose Hybrid as the type.
  4. Write your script in the editor or upload an existing script.
  5. Click on Save to save the runbook.
  6. Click on the Schedule pane to schedule your runbook.
  7. Choose a schedule type, such as a recurring schedule or a one-time schedule.
  8. Set the schedule details, such as the start time, end time, and time zone.
  9. Click on Create to create the schedule for your runbook.

Using Azure CLI Commands for Hybrid Runbook Workers

Here are some Azure CLI commands that you can use for Hybrid Runbook Workers:

  • To download the Hybrid Runbook Worker software:
az automation hybrid-worker download --os-type <os_type>

To register the Hybrid Runbook Worker:

az automation hybrid-worker register --resource-group <resource_group_name> --automation-account-name <account_name> --name <worker_name> --key <key>

To create a Hybrid Runbook:

az automation runbook create --account-name <account_name> --resource-group <resource_group_name> --name <runbook_name> --type HybridWorker --tags <tags> --log-analytics <log_analytics_workspace>

To schedule a Hybrid Runbook:

az automation schedule create --account-name <account_name> --resource-group <resource_group_name> --schedule-name <schedule_name> --start-time <start_time> --timezone <timezone> --frequency <frequency> --interval <interval> --hybrid-worker-group-name <group_name> --hybrid-worker-name <worker_name>

To monitor a Hybrid Runbook:

az automation job list --account-name <account_name> --resource-group <resource_group_name> --runbook-name <runbook_name> --top <top> --orderby <orderby> --hybrid-worker-group-name <group_name> --hybrid-worker-name <worker_name>

These are just a few examples of the many Azure CLI commands available for Hybrid Runbook Workers. You can find more information on the Azure CLI documentation page.

I hope this tutorial has been helpful to you in understanding Azure Automation and using CLI commands. If you have any further questions or require additional assistance, feel free to ask!