Run Azure CLI commands in PowerShell 7.2 runbooks

You can run Azure CLI commands in runbooks linked with PowerShell 7.2 Runtime environment.

Note

Azure CLI commands version 2.56.0 are available as a default package in PowerShell 7.2 Runtime environment.

Prerequisites

  • An Azure Automation account (in any supported Public regions except Central India, Germany North, Italy North, Israel Central, Poland Central, UAE Central, and Government clouds).

Create Runtime environment

Note

Instead of creating a new PowerShell 7.2 Runtime environment, you can use the System-generated PowerShell 7.2 Runtime environment.

  1. Sign in to the Azure portal and select your Automation account.

  2. Under Process Automation, select Runtime Environments (preview) and then select Create.

  3. On Basics tab, provide the following details:

    1. Provide Name for the Runtime environment. It must begin with alphabet and can contain only alphabets, numbers, underscores, and dashes.
    2. From the Language dropdown list, select PowerShell.
    3. In Runtime version for scripting language, select 7.2
    4. Provide appropriate Description.
  4. On Packages tab, in the Package version dropdown list, you would see Az version 8.3 and Azure CLI version 2.56.0 already present.

  5. Select +Add from gallery to add more packages from gallery and select Next.

  6. On Review + create tab, review the entries and select Create.

    A notification appears to confirm that a Runtime environment is successfully created.

    Screenshot shows how to create a runtime environment.

Create Runbook

You can create a new PowerShell runbook that supports Azure CLI commands and is associated with PowerShell 7.2 Runtime environment.

To create a runbook, follow these steps:

In your Automation account, under Process Automation, select Runbooks.

  1. Select Create.

  2. In the Basics tab, you can either create a new runbook or upload a file from your local computer or from PowerShell gallery.

    1. Provide a Name for the runbook. It must begin with a letter and can contain only letters, numbers, underscores, and dashes.

    2. From the Runbook type dropdown, select the type of runbook that you want to create.

    3. Select PowerShell 7.2 Runtime environment created earlier.

    4. Provide appropriate Description.

      Screenshot shows how to create runbook in runtime environment.

  3. Add runbook code on the Edit Runbook page and select Save.

  4. Test runbook execution in Test pane. After you confirm the results, select Publish to publish the runbook and execute it.

Next steps