Being able to quickly swap out the OS disk of an Azure VM is a feature that means VMs don’t have to be ‘killed’ and rebuilt when there is a problem or a need for major revisioning of the VM. A backup OS managed disk, or a new OS managed disk, or an ‘earlier’ OS managed disk version can be applied in situ to the provisioned VM. We keep a repository of key versions of OS and Data disk snapshots that can be quickly turned into unattached managed disks when needed for fixing a VM.

#1. Login to Azure

#2. Declare Variables

#3. Get the VM and new managed OS disk

#4. The VM should be stopped and deallocated

#5. Swap out the OS Disk

#6. Update the VM

#7. Start the VM

This is a screen shot of the initial OS disk used in the VM ‘DemoOSSwap-2016‘:

This is the swapped OS Disk in the same VM: