Applies to: ✔️ Linux VMs ✔️ Windows VMs
The following steps describe how to change the availability set of a virtual machine (VM) by using Azure PowerShell. You can add a VM to an availability set only when you're creating the VM. To change the availability set, you need to delete and then re-create the VM.
This article was last tested on February 12, 2019 by using Azure Cloud Shell and the Az PowerShell module version 1.2.0.
Warning
This is just an example. In some cases, you'll need to update it for your specific deployment.
Make sure the disks are set to detach
as the delete option. If they're set to delete
, update the VMs before you delete the VMs.
If your VM is attached to a load balancer, you need to update the script to handle that case.
Some extensions might also need to be reinstalled after you finish this process.
If your VM uses hybrid benefits, you need to update the example to enable hybrid benefits on the new VM.