Assigning Availability Set At The Time Of Creation Of VM
Articles on: Virtual Machine
Assigning Availability Set At The Time Of Creation Of VM
At the point of creation of a VM in a cloud, you’ll get an option to put that VM in a specific Availability Set. After the creation of VM you can’t change its availability set or to put it in a new one through GUI..
Change The Availability Set Using PowerShell
A VM can only be added to an availability set when it is created. In order to change the availability set, you need to delete and recreate the virtual machine.
- Capture the following key details from the VM to be modified.
Name of the VM
undefined $vm = Get-AzureRmVM -ResourceGroupName -Name $vm.Name
VM Size
undefined $vm.HardwareProfile.VmSize
Network primary network interface and optional network interfaces if they exist on the VM
undefined $vm.NetworkProfile.NetworkInterfaces[0].Id
OS Disk Profile
undefined $vm.StorageProfile.OsDisk.OsType $vm.StorageProfile.OsDisk.Name $vm.StorageProfile.OsDisk.Vhd.Uri
Disk profiles for each data disk
undefined $vm.StorageProfile.DataDisks[].Lun $vm.StorageProfile.DataDisks[].Vhd.Uri
VM extensions installed
undefined $vm.Extensions
- Delete the VM without deleting any of the disks or the network interfaces.
undefined Remove-AzureRmVM -ResourceGroupName -Name
- Create the availability set if it does not already exist
undefined New-AzureRmAvailabilitySet -ResourceGroupName -Name -Location ""
- Recreate the VM using the new availability set
undefined $vm2 = New-AzureRmVMConfig -VMName -VMSize -AvailabilitySetId Set-AzureRmVMOSDisk -CreateOption "Attach" -VM -VhdUri -Name [-Windows | -Linux] Add-AzureRmVMNetworkInterface -VM -Id New-AzureRmVM -ResourceGroupName -Location -VM
Updated on: 31/01/2023
Updated on: 01/07/2024
Thank you!