我尝试将带有托管磁盘的现有Azure VM移动到现有可用性集中。但是,当我应用命令时:
New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Location -VM $NewVM -DisableBginfoExtension
我收到以下错误:
New-AzureRmVM:更改属性&#; osDisk.name'不被允许。 ErrorCode:PropertyChangeNotAllowed ErrorMessage:更改属性&#; osDisk.name'不被允许。 StatusCode:409 ReasonPhrase:冲突 OperationID:c179070b-e189-4025-84b0-87ba748f5844 在行:2 char:5 + New-AzureRmVM -ResourceGroupName $ rg -Location $ OriginalVM.Locati ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + CategoryInfo:CloseError:(:) [New-AzureRmVM],ComputeCloudException + FullyQualifiedErrorId:Microsoft.Azure.Commands.Compute.NewAzureVMCommand
答案 0 :(得分:1)
在Azure中,一旦磁盘连接到VM,就无法更改磁盘的名称。操作系统磁盘将获取您在创建VM期间提供的VM名称。您可以参考this link查找更多详细信息。
我做了一个测试并重现了与你相同的错误。因为我用Set-AzureRmVMOSDisk
更改了操作系统磁盘名称。然后我删除了更改操作系统磁盘名称并成功的cmdlet。
您可以参考创建vm而不更改操作系统磁盘名称,如下面的cmdlet:
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows
我使用的整个powershell cmdlet:
#Provide the subscription Id
$subscriptionId = 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx'
$resourceGroupName ='yangsatest'
$diskName = 'VM1_OsDisk_1_xxxxxxxxxxxx'
$location = 'eastus'
$virtualNetworkName = 'yangsatest-vnet'
$virtualMachineName = 'VM2'
$virtualMachineSize = 'Standard_A1'
Select-AzureRmSubscription -SubscriptionId $SubscriptionId
$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -DiskName $diskName
$VirtualMachine = New-AzureRmVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize -AvailabilitySetId /subscriptions/xxxxx-xxxxxx-xxx-xxxx8-xxxxxx/resourceGroups/yangsatest/providers/Microsoft.Compute/availabilitySets/Myset
#Use the Managed Disk Resource Id to attach it to the virtual machine. Please change the OS type to linux if OS disk has linux OS
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows
$publicIp = New-AzureRmPublicIpAddress -Name ($VirtualMachineName.ToLower()+'_ip') -ResourceGroupName $resourceGroupName -Location $location -AllocationMethod Dynamic
$vnet = Get-AzureRmVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName
$nic = New-AzureRmNetworkInterface -Name ($VirtualMachineName.ToLower()+'_nic') -ResourceGroupName $resourceGroupName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id
$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $nic.Id
#Create the virtual machine with Managed Disk
New-AzureRmVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $location
---------- ----------更新 更新脚本以适合官方文档:更改托管Windows VM的可用性(https://docs.microsoft.com/en-us/azure/virtual-machines/windows/change-availability-set):
#set variables
$rg = "demo-resource-group"
$vmName = "demo-vm"
$newAvailSetName = "demo-as"
$outFile = "C:\temp\outfile.txt"
#Get VM Details
$OriginalVM = get-azurermvm -ResourceGroupName $rg -Name $vmName
#Output VM details to file
"VM Name: " | Out-File -FilePath $outFile
$OriginalVM.Name | Out-File -FilePath $outFile -Append
"Extensions: " | Out-File -FilePath $outFile -Append
$OriginalVM.Extensions | Out-File -FilePath $outFile -Append
"VMSize: " | Out-File -FilePath $outFile -Append
$OriginalVM.HardwareProfile.VmSize | Out-File -FilePath $outFile -Append
"NIC: " | Out-File -FilePath $outFile -Append
$OriginalVM.NetworkProfile.NetworkInterfaces.Id | Out-File -FilePath $outFile -Append
"OSType: " | Out-File -FilePath $outFile -Append
$OriginalVM.StorageProfile.OsDisk.OsType | Out-File -FilePath $outFile -Append
"OSDisk: " | Out-File -FilePath $outFile -Append
$OriginalVM.StorageProfile.OsDisk.ManagedDisk.Id| Out-File -FilePath $outFile -Append
if ($OriginalVM.StorageProfile.DataDisks) {
"Data Disk(s): " | Out-File -FilePath $outFile -Append
$OriginalVM.StorageProfile.DataDisks.Id | Out-File -FilePath $outFile -Append
}
#Remove the original VM
Remove-AzureRmVM -ResourceGroupName $rg -Name $vmName
#Create new availability set if it does not exist
$availSet = Get-AzureRmAvailabilitySet -ResourceGroupName $rg -Name $newAvailSetName -ErrorAction Ignore
if (-Not $availSet) {
$availset = New-AzureRmAvailabilitySet -ResourceGroupName $rg -Name $newAvailSetName -Location $OriginalVM.Location -Managed -PlatformFaultDomainCount 2 -PlatformUpdateDomainCount 2
}
#Create the basic configuration for the replacement VM
$newVM = New-AzureRmVMConfig -VMName $OriginalVM.Name -VMSize $OriginalVM.HardwareProfile.VmSize -AvailabilitySetId $availSet.Id
Set-AzureRmVMOSDisk -VM $NewVM -ManagedDisk $OriginalVM.StorageProfile.OsDisk.ManagedDisk.Id -CreateOption Attach -Windows
#Add Data Disks
foreach ($disk in $OriginalVM.StorageProfile.DataDisks ) {
Add-AzureRmVMDataDisk -VM $newVM -Name $disk.Name -ManagedDiskId $OriginalVM.StorageProfile.DataDisks.Id -Caching $disk.Caching -Lun $disk.Lun -CreateOption Attach -DiskSizeInGB $disk.DiskSizeGB
}
#Add NIC(s)
foreach ($nic in $OriginalVM.NetworkProfile.NetworkInterfaces.Id) {
Add-AzureRmVMNetworkInterface -VM $NewVM -Id $nic
}
#Create the VM
New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Location -VM $NewVM -DisableBginfoExtension
答案 1 :(得分:0)
对我来说,问题是我创建了一个托管磁盘(从Azure Portal),选择了错误的操作系统,导致此问题,然后使用正确的操作系统重新创建了托管磁盘,然后进行了部署。