In my previous post I showed you how we can export Azure resource groups into ARM templates using the Azure Portal. For those of us who are not GUI fans (including myself) Azure PowerShell and Azure CLI provide cmdlets/commands to leverage the export feature for cloning, redeploying and automating Azure resource group deployments.
Azure PowerShell
With the latest Azure PowerShell you can execute below cmdlet to export a running resource group to an ARM template.
Export-AzureRmResourceGroup -ResourceGroupName <RG name> -Path <template path>
To export resource groups from a previous deployment you may use the below cmdlet syntax.
Save-AzureRmResourceGroupDeploymentTemplate -DeploymentName <Deployment Name> -ResourceGroupName <RG Name>-Path <template path>
Azure CLI
You can use the following syntax to export a running resource group to an ARM template.
azure group export <name> [template path]
Use below command syntax to export to an ARM template from a previously deployed Resource Group
group deployment template download [options] <resource-group> <name> [directory]