title | titleSuffix | description | services | ms.date | ms.topic | ms.custom |
---|---|---|---|---|---|---|
Add support for Azure CLI in PowerShell 7.2 runbooks in Runtime environment |
Azure Automation |
This article shows how to add support for Azure CLI in PowerShell 7.2 runbooks in Runtime environment. |
automation |
01/17/2024 |
conceptual |
references_regions, devx-track-azurecli |
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.
- 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).
Note
Instead of creating a new PowerShell 7.2 Runtime environment, you can use the System-generated PowerShell 7.2 Runtime environment.
-
Sign in to the Azure portal and select your Automation account.
-
Under Process Automation, select Runtime Environments (preview) and then select Create.
-
On Basics tab, provide the following details:
- Provide Name for the Runtime environment. It must begin with alphabet and can contain only alphabets, numbers, underscores, and dashes.
- From the Language dropdown list, select PowerShell.
- In Runtime version for scripting language, select 7.2
- Provide appropriate Description.
-
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.
-
Select +Add from gallery to add more packages from gallery and select Next.
-
On Review + create tab, review the entries and select Create.
A notification appears to confirm that a Runtime environment is successfully created.
:::image type="content" source="./media/quickstart-cli-support-powershell-runbook-runtime-environment/create-runtime-environment.png" alt-text="Screenshot shows how to create a runtime environment." lightbox="./media/quickstart-cli-support-powershell-runbook-runtime-environment/create-runtime-environment.png":::
Azure CLI version 2.56.0 is available only for PowerShell 7.2 Runtime environment.
PUT
https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.Automation/automationAccounts/<accountName>/runtimeEnvironments/<runtimeEnvironmentName>?api-version=2023-05-15-preview
{
"properties": {
"runtime": {
"language": "PowerShell",
"version": "7.2"
},
"defaultPackages": {
"Az": "8.3.0",
"Azure CLI": "2.56.0"
}
},
"name": "<runtimeEnvironmentName>"
}
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.
-
Select Create.
-
In the Basics tab, you can either create a new runbook or upload a file from your local computer or from PowerShell gallery.
-
Provide a Name for the runbook. It must begin with a letter and can contain only letters, numbers, underscores, and dashes.
-
From the Runbook type dropdown, select the type of runbook that you want to create.
-
Select PowerShell 7.2 Runtime environment created earlier.
-
Provide appropriate Description.
:::image type="content" source="./media/manage-runtime-environment/create-runbook.png" alt-text="Screenshot shows how to create runbook in runtime environment." lightbox="./media/manage-runtime-environment/create-runbook.png":::
-
-
Add runbook code on the Edit Runbook page and select Save.
-
Test runbook execution in Test pane. After you confirm the results, select Publish to publish the runbook and execute it.
You can create runbooks and link with PowerShell 7.2 Runtime environment.
PUT
https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.Automation/automationAccounts/<accountName>/runbooks/<runbookName>?api-version=2023-05-15-preview
{
"properties": {
"runbookType": "PowerShell",
"runtimeEnvironment": <runtimeEnvironmentName>,
"publishContentLink": {
"uri": "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-automation-runbook-getvms/Runbooks/Get-AzureVMTutorial.ps1"
}
},
"location": "East US"
}
- See Manage Runtime environment to view the various operations through portal and REST API.