I'm trying to move an existing Azure VM with a Managed Disk into an existing Availability Set. However, when I apply the command:
New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Location -VM $NewVM -DisableBginfoExtension
I get the following error:
New-AzureRmVM : Changing property 'osDisk.name' is not allowed. ErrorCode: PropertyChangeNotAllowed ErrorMessage: Changing property 'osDisk.name' is not allowed. StatusCode: 409 ReasonPhrase: Conflict OperationID : c179070b-e189-4025-84b0-87ba748f5844 At line:2 char:5 + New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Locati ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzureRmVM], ComputeCloudException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
In Azure ,once the disk is attached to the VM ,there is no way to change the name of the disk. The OS disk will get the name of the VM as provided by you during the creation of the VM. You can refer to this link to find more details.
I did a test and reproduced the same error as yours. Because I changed the OS disk name with
Set-AzureRmVMOSDisk
. Then I deleted the cmdlet which changed the OS disk’s name and succeed.You can refer to create the vm without changing the OS disk name like the following cmdlet:
The whole powershell cmdlet I used :
----------Update---------- Updating Script to fit Official document :Change the availability set for a Managed Windows VM(https://docs.microsoft.com/en-us/azure/virtual-machines/windows/change-availability-set):
for me the problem was that I created a Managed Disk (from Azure Portal) which I selected the wrong OS which caused me this , I re-created managed disk with the right OS and then deployment worked.