How to Schedule and Automate Your Virtual Machine Size with Azure Automation Accounts
Are you looking to optimize cloud costs and performance? Learn how to automatically resize your Azure Virtual Machines (VMs) using Azure Automation Accounts.
Managing cloud resources efficiently is key to optimizing performance and controlling costs. In this guide, you’ll learn how to automate Azure VM resizing using Azure Automation Accounts and Runbooks. Whether you’re scaling up for high-traffic hours or scaling down after hours, this tutorial shows you how to schedule automatic virtual machine size changes based on your business needs — no manual intervention required.
Step 1:
Go to Azure portal and search for Automation Accounts.
Step 2:
Click on Create Automation Account.
Step 3:
Enter the detail and click on Review + Create.
Step 4:
Verify detail and click on Create and wait for the deployment to be complete.
Step 5:
Once deployment is complete, Click on Go to Resource.
Step 6:
Search Identity and copy Object ID.
Step 7:
Go to the Resource Group of VM you want to Automatically Resize.
Access Control (IAM) -> Add Role Assignment
Step 8:
On the Job function roles, select Virtual Machine Contributor.
Step 9:
Go to the members tab and select Managed Identity then select Review + Assign.
Step 10:
Now go back to Automation Account which was created earlier. Then Go to Runbooks and Create a runbook.
Step 11:
Fill the details and click review and create.
Step 12:
Enter the following command in the Runbook by entering your VM’s Resource Group, VM Name, New VM Size and then click Publish.
param ( [string]$ResourceGroupName = "VM Resource Group", [string]$VMName = "VM Name", [string]$NewVMSize = "New VM Size" ) # Login to Azure Connect-AzAccount -identity # Stop the VM Stop-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName -Force # Update VM size $vm = Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName $vm.HardwareProfile.VmSize = $NewVMSize Update-AzVM -ResourceGroupName $ResourceGroupName -VM $vm # Start the VM Start-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName Write-Output "VM $VMName resized to $NewVMSize"
Step 13:
Schedule VM to resize automatically.
Go to Schedules then Add a Schedule then link Runbook with your schedule.
Note: You can create multiple runbooks within the same Automation Account by following the same steps and schedule them as needed. For example, you might want your VM to run with 16 GB RAM in the morning and 4 GB RAM at night.
Please be aware that the virtual machine will reboot to apply the size changes according to the defined schedules.
Conclusion
Automating your Azure Virtual Machine resizing with Automation Accounts and Runbooks is a smart way to optimize performance, reduce costs, and streamline resource management. With just a few steps, you can take full control over your VM scaling strategy and align your cloud infrastructure with your business needs.
Need expert help implementing Azure automation or scaling your cloud infrastructure?
Partner with ITCS—your trusted technology partner for secure, scalable, and cost-efficient IT solutions in Pakistan.
📩 Contact us today to discuss how we can support your digital transformation goals.