How to automate On-Demand Azure Backup for Azure Virtual Machines using PowerShell
                This guest post is authored by Swathi Dhanwada, Customer Engineer 2, who is frequently seen answering Azure Backup community queries.
Azure Backup supports multiple backups of Azure Virtual Machines per day using Enhanced Policy. For hourly backup, the minimum RPO is 4 hours and the maximum is 24 hours. You can set the backup schedule to 4, 6, 8, 12, and 24 hours respectively. Learn how to back up an Azure VM using Enhanced policy. This feature is only available to unprotected VMs that are new to Azure Backup. VMs that are already protected with existing policy can't be moved to Enhanced policy. To overcome this, you can run an multiple on-demand backup of a VM per day after you set up its protection. Keep these details in mind:
- If the initial backup is pending, on-demand backup creates a full copy of the VM in the Recovery Services vault.
 - If the initial backup is complete, an on-demand backup will only send changes from the previous snapshot to the Recovery Services vault. That is, later backups are always incremental.
 - You can’t trigger on-demand backups by disabling scheduled backup.
 
Below are the steps to automate the on-demand backup for azure virtual machines using Azure Automation.
Step1
Create an Automation resource with system managed identity. To assign permissions to managed identities, complete the following steps:
- 
Sign in to Azure interactively using the Connect-AzAccount cmdlet and follow the instructions:
 
- Provide an appropriate value for the following variables and then run the script:
 
- Use the PowerShell 
cmdletNew-AzRoleAssignment to assign a role to the system-assigned managed identity: 
Step2
Verify if required modules are imported to the Automation resource. If not, import the following modules from the Modules gallery in the order given below:
Step3
Create PowerShell Runbooks in the Automation Resource. You can create multiple Runbooks based on which set of virtual machines you want to protect.
Step4
Edit the Runbook and write script to choose which virtual machines to take a backup. You can create scripts that suit your requirements.
Script to trigger on demand backup for single vm
- Save the script.
 - Test the script using “Test Pane”.
 - Publish the Runbook.
 
Step5
- Schedule the Runbook. While scheduling the Runbook, you can pass on the parameters required for the PowerShell Script.
 - The sample script takes the retention as an input. So, if you need to schedule a weekly snapshot and retain for 8 weeks, create a weekly schedule as mentioned below and specify the retention as 56 days (8 weeks). You can create monthly and yearly schedules (run every 12 months) in a similar manner. You can monitor the success/failure of these backups using the “Jobs” tab of Runbooks.
 
Reference Documents:
Published on:
Learn moreRelated posts
Accelerate Your Growth: Azure Cosmos DB Partner Acceleration Program
Accelerate Your Growth: Azure Cosmos DB Partner Acceleration Program Unlock 360° Success with the Cosmos DB Engineering Team Are you ready to ...
Transforming Field Operations with AI, Azure Maps & Dynamics 365
Efficient field operations are the backbone of successful, data-driven organizations. Yet, many businesses continue to struggle with scattered...
Failures Happen in Cloud, but how Azure Cosmos DB keeps your Applications Online
The only thing that’s constant in distributed systems is failures. No cloud platform is immune to failures — from regional outages and transie...
The `azd` extension to configure GitHub Copilot coding agent integration with Azure
This post shares how to set up the GitHub Copilot coding agent integration with Azure resources and services by using the Azure Developer CLI ...
Announcing Azure MCP Server 1.0.0 Stable Release – A New Era for Agentic Workflows
Today marks a major milestone for agentic development on Azure: the stable release of the Azure MCP Server 1.0! The post Announcing Azure MCP ...
From Backup to Discovery: Veeam’s Search Engine Powered by Azure Cosmos DB
This article was co-authored by Zack Rossman, Staff Software Engineer, Veeam; Ashlie Martinez, Staff Software Engineer, Veeam; and James Nguye...
Azure SDK Release (October 2025)
Azure SDK releases every month. In this post, you'll find this month's highlights and release notes. The post Azure SDK Release (October 2025)...
Microsoft Copilot (Microsoft 365): [Copilot Extensibility] No-Code Publishing for Azure AI Foundry Agents to Microsoft 365 Copilot Agent Store
Developers can now publish Azure AI Foundry Agents directly to the Microsoft 365 Copilot Agent Store with a simplified, no-code experience. Pr...
Azure Marketplace and AppSource: A Unified AI Apps and Agents Marketplace
The Microsoft AI Apps and Agents Marketplace is set to transform how businesses discover, purchase, and deploy AI-powered solutions. This new ...