Is it possible to get a PowerShell script that represents an operation in Azure Portal?

DZIANIS DEV 20 Reputation points
2024-08-07T13:13:23.27+00:00

Hello,

When I use Azure Portal and trigger some operation, like Deployment of Azure AI multiservice account, I would like to get a PowerShell script that represents that operation. Is that possible?

In the "Overview" of the deployment operation I see that I can get ARM Template with Inputs and Outputs. That is very useful. But is it possible to do the same but for PowerShell?

Regards,

Dzianis

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,256 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,579 questions
{count} votes

Accepted answer
  1. Pranay Reddy Madireddy 365 Reputation points Microsoft Vendor
    2024-09-26T02:17:46.14+00:00

    Hii DZIANIS DEV

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    In the Azure Portal, after finishing a deployment, you can download the ARM template by navigating to the "Deployments" section of your resource group, selecting the specific deployment, and then clicking on the "Overview" tab where you'll find the option to download the template.

    You can manually convert an ARM template into a PowerShell script by using Azure PowerShell commands. This involves creating a script with commands such as "New-AzResourceGroupDeployment" to set up the resources defined in the ARM template.

    Example of Converting an ARM Template to a PowerShell Script:-

    {

      "$schema": "https://schema.management.azure.com/2019-04-01/deploymentTemplate.json#",

      "contentVersion": "1.0.0.0",

      "resources": [

        {

          "type": "Microsoft.Storage/storageAccounts",

          "apiVersion": "2021-04-01",

          "name": "mystorageaccount",

          "location": "West US",

          "sku": {

            "name": "Standard_LRS"

          },

          "kind": "StorageV2",

          "properties": {}

        }

      ]

    }

    PowerShell Script Example:-

     Define parameters:-

    $resourceGroupName = "myResourceGroup"

    $location = "West US"

    $storageAccountName = "mystorageaccount"

    Deploy the storage account:-

    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName `

        -TemplateFile "path_to_your_template.json" `

        -storageAccountName $storageAccountName `

        -Location $location

    Azure CLI Alternative:-

    If you’re open to using Azure CLI instead of PowerShell, you can deploy ARM templates with the AZ deployment group create command. This command is similar to its PowerShell counterpart but follows Azure CLI syntax.

    Azure CLI Example:-

    az group create --name myResourceGroup --location "West US"

    az deployment group create --resource-group myResourceGroup --template-file path_to_your_template.json.

    For reference, please review this documentation:- https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/quickstart-create-templates-use-visual-studio-code?tabs=CLI

    https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/manage-resources-powershell

    Manage resources - Azure PowerShell - Azure Resource Manager | Microsoft Learn

    If you have any further queries, do let us know.


    If the answer is helpful, please click "Accept Answer" and "Upvote it".

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.