Share via

Creating azure automation run book with PShell to deploy new instance of cloud compute solution and delete with other script

Varma 1,560 Reputation points
2024-07-09T10:37:31.8866667+00:00

is it possible to azure automation run book using powershell to deploy new instance of cloud compute solution?

and I want to run another run book to delete all the resources created by the first script with out any back up ?

how do we do these 2, please suggest

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 41,386 Reputation points MVP Volunteer Moderator
    2026-04-17T19:07:32.8066667+00:00

    Hello Varma !

    Thank you for posting on MS Learn Q&A.

    You can use one PS runbook to deploy resources and another runbook to delete them.

    Azure Automation supports PS runbooks, and Microsoft documents using a runbook to deploy Azure resources from an ARM template. It also supports managed identity so the runbook can authenticate to Azure without storing credentials.

    To deploy runbook, you need to authenticate with the automation account managed identity and create your resources by deploying an ARM template, Bicep or direct Az PS commands. Then put everything in a dedicated resource group if possible

    To delete runbook, authenticate the same way and delete the whole resource group or delete individual resources if needed. If you delete the resource group, Azure removes all resources in it

    The delete the whole resource group approach is usually best because it is simpler and avoid missing dependent resources.

    # Deploy runbook
    Connect-AzAccount -Identity
    $rg = "rg-cloudcompute-dev-01"
    $location = "westeurope"
    New-AzResourceGroup -Name $rg -Location $location -Force
    New-AzResourceGroupDeployment `
      -ResourceGroupName $rg `
      -TemplateFile "C:\Templates\main.json" `
      -TemplateParameterFile "C:\Templates\main.parameters.json"
    
    # Delete runbook
    Connect-AzAccount -Identity
    $rg = "rg-cloudcompute-dev-01"
    Remove-AzResourceGroup -Name $rg -Force
    
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

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