Hi @Dhishyanth.
You can delete the vm and recreate in a different availability set. You can use the following powershell code:
# Set variables
$resourceGroup = "myResourceGroup"
$vmName = "myVM"
$newAvailSetName = "myAvailabilitySet"
# Get the details of the VM to be moved to the Availability Set
$originalVM = Get-AzVM `
-ResourceGroupName $resourceGroup `
-Name $vmName
# Create new availability set if it does not exist
$availSet = Get-AzAvailabilitySet `
-ResourceGroupName $resourceGroup `
-Name $newAvailSetName `
-ErrorAction Ignore
if (-Not $availSet) {
$availSet = New-AzAvailabilitySet `
-Location $originalVM.Location `
-Name $newAvailSetName `
-ResourceGroupName $resourceGroup `
-PlatformFaultDomainCount 2 `
-PlatformUpdateDomainCount 2 `
-Sku Aligned
}
# Remove the original VM
Remove-AzVM -ResourceGroupName $resourceGroup -Name $vmName
# Create the basic configuration for the replacement VM
$newVM = New-AzVMConfig `
-VMName $originalVM.Name `
-VMSize $originalVM.HardwareProfile.VmSize `
-AvailabilitySetId $availSet.Id
Set-AzVMOSDisk `
-VM $newVM -CreateOption Attach `
-ManagedDiskId $originalVM.StorageProfile.OsDisk.ManagedDisk.Id `
-Name $originalVM.StorageProfile.OsDisk.Name `
-Windows
# Add Data Disks
foreach ($disk in $originalVM.StorageProfile.DataDisks) {
Add-AzVMDataDisk -VM $newVM `
-Name $disk.Name `
-ManagedDiskId $disk.ManagedDisk.Id `
-Caching $disk.Caching `
-Lun $disk.Lun `
-DiskSizeInGB $disk.DiskSizeGB `
-CreateOption Attach
}
# Add NIC(s) and keep the same NIC as primary
foreach ($nic in $originalVM.NetworkProfile.NetworkInterfaces) {
if ($nic.Primary -eq "True")
{
Add-AzVMNetworkInterface `
-VM $newVM `
-Id $nic.Id -Primary
}
else
{
Add-AzVMNetworkInterface `
-VM $newVM `
-Id $nic.Id
}
}
#Recreate the VM
New-AzVM `
-ResourceGroupName $resourceGroup `
-Location $originalVM.Location `
-VM $newVM `
-DisableBginfoExtension
Hope this helps!!
If you need to know more about Azure, enroll with Microsoft Azure training course today.
Thank you!!