Automating Disk Snapshots


There are two ways to backup your Azure Virtual Machines: First method is using the Azure Backup service in order to backup Virtual Machine periodically based on a backup policy. The Azure Backup service backs up data from on-premises machines, and Azure VMs. Data can be backed up and recovered at a granular level. Second method is creating VM disk snapshots in order to backup a disk manually. It is great when you try to backup a VM for which Azure Backup can not be used.

In this article, I will explain the second option in order to automate the process of creating disk snapshots using PowerShell.

Creating Azure Runbook

In this article, I will create daily snapshots of the disks which have associated tagname ‘Snapshot’ with tagvalue ‘True’. First, we have to create the tag on the Virtual Machines that must be snapshotted. Open the Azure Portal, navigate to the Virtual Machine blade and ‘Tags’:

Creating Azure Runbook

Now, we can create the Runbook from the Azure Automation blade. If you don’t already have an existing automation account, then create a new one.

Click ‘+ Create a runbook


And enter the following information:

  • Name: It is a friendly name for the Runbook
  • Runbook Type: Select PowerShell in this case, but you can select another type if needed
  • Description: it is optional, but you can describe the goal of this runbook

Runbook name

The runbook is created, but before going deeper, we must update the modules. Go to ‘Modules gallery’ and search for ‘AzureRM.Resource’ which is a module we need in the runbook.

Une image contenant capture d’écran Description générée automatiquement

In order to import the module, click ‘Import


Before validating the wizard, select the checkbox in order to update all the modules.

Agree to update all the modules

Go back to the ‘Modules’ blade and confirm that the module is available


Now, edit the runbook and copy/paste the following PowerShell code.

Publish the Runbook when everything is ok, and then go back to the Azure Automation Account and select Schedules. Click on ‘Link to schedule’.


Link to schedule

You can confirm the schedule is created

Schedule is created

VSAN from StarWind eliminates any need for physical shared storage just by mirroring internal flash and storage resources between hypervisor servers. Furthermore, the solution can be run on the off-the-shelf hardware. Such design allows VSAN from StarWind to not only achieve high performance and efficient hardware utilization but also reduce operational and capital expenses.

Learn more about ➡ VSAN from StarWind

You just need to wait until the runbook start, then a snapshot will be created

Create disk snapshot


Thanks to Azure Automation, you can very easily and quickly deploy a Runbook to backup a Virtual Machine. You can also automate tasks that you performed manually.

Thanks for reading!

Views All Time
Views Today
Appreciate how useful this article was to you?
1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5
5 out of 5, based on 1 review
Back to blog
The following two tabs change content below.
Nicolas Prigent
Nicolas Prigent
Nicolas Prigent works as an IT Production Manager, based in Paris, with a primary focus on Microsoft technologies. Nicolas is a three-time Microsoft MVP in Cloud and Datacenter Management with 10 years experience in administering Windows products. He also received the "PowerShell Heroes 2016" Award.