What is Azure Automation Account?
An Azure Automation account is a cloud-based management solution offered by Microsoft Azure for automating tasks and processes across Azure resources and other third-party systems. It provides a centralized location to create, deploy, manage, and monitor workflows, runbooks, and scripts to perform repetitive tasks, orchestrate complex processes, and reduce manual errors.
Overall, the Azure Automation account is a powerful tool for managing and automating IT operations and business processes, improving efficiency, reducing costs, and minimizing errors.
Some key features:
- Workflow Automation: Azure Automation allows you to automate a wide range of tasks, from simple script execution to complex process automation across hybrid environments, using various workflow tools such as PowerShell, Python, and Azure Logic Apps.
- Configuration Management: Azure Automation enables you to manage and apply consistent configurations across Azure and on-premises resources by using Desired State Configuration (DSC).
- Monitoring and Reporting: Azure Automation provides comprehensive monitoring and reporting capabilities, including alerting, logging, and reporting, to help you detect and resolve issues quickly and efficiently.
- Integration with Other Azure Services: Azure Automation can be integrated with other Azure services, such as Azure Virtual Machines, Azure Functions, and Azure Storage, to automate workflows and improve efficiency.
In the below sample, I wanna describe how to config a scheduled task for Stop and Start a VM with the PowerShell runbook.
- Create an Azure Automation account: Go to the Azure portal and create an Automation account. You can do this by searching for “Automation” in the search bar and clicking on “Automation accounts” under the “Services” category. Then click “Add” and follow the prompts to create an Automation account.
- Import the AzureRM modules: In your Azure Automation account, click on “Modules” in the left-hand menu and then click “Browse gallery”. Search for “AzureRM.Compute” and “AzureRM.Profile” modules, and then click “Import” to import them into your Automation account.
- Create a new runbook: Click on “Runbooks” in the left-hand menu and then click “Create a runbook”. Give your runbook a name and select “PowerShell” as the runbook type.
- Add the PowerShell script: In the editor, copy and paste the following PowerShell script
Connect to Azure
$connection = Get-AutomationConnection -Name 'AzureRunAsConnection'
Connect-AzAccount -ServicePrincipal -Tenant $connection.TenantID -ApplicationId $connection.ApplicationID -CertificateThumbprint
$connection.CertificateThumbprint
Stop the VM
Stop-AzVM -ResourceGroupName "myResourceGroup" -Name "myVMName" -Force
Start the VM
Start-AzVM -ResourceGroupName "myResourceGroup" -Name "myVMName"
Replace “myResourceGroup” and “myVMName” with the name of your resource group and VM.
- Create a schedule: Click on “Schedules” in the left-hand menu and then click “Add a schedule”. Give your schedule a name, set the recurrence and start time, and select the runbook you just created.
That’s it! Your VM will now automatically stop and start according to the schedule you set up. You can also use similar PowerShell scripts to perform other automation tasks, such as resizing VMs or backing up data.