得到错误“不允许更改属性'osDisk.name'."使用Azure Powershell脚本 [英] Getting error "Changing property 'osDisk.name' is not allowed." with Azure Powershell Script

查看:66
本文介绍了得到错误“不允许更改属性'osDisk.name'."使用Azure Powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将具有托管磁盘的现有Azure VM移至现有可用性集.但是,当我应用命令时:

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

我收到以下错误:

New-AzureRmVM:不允许更改属性"osDisk.name". 错误代码:PropertyChangeNotAllowed 错误消息:不允许更改属性"osDisk.name". 状态码:409 ReasonPhrase:冲突 操作ID:c179070b-e189-4025-84b0-87ba748f5844 在线:2字符:5 + New-AzureRmVM -ResourceGroupName $ rg-位置$ OriginalVM.Locati ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~ + CategoryInfo:CloseError:(:) [New-AzureRmVM],ComputeCloudException + FullyQualifiedErrorId:Microsoft.Azure.Commands.Compute.NewAzureVMCommand

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

推荐答案

在Azure中,一旦将磁盘连接到VM,就无法更改磁盘名称. OS磁盘将获得您在创建VM时提供的VM的名称.您可以参考

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.

我进行了测试,并重现了与您相同的错误.因为我用Set-AzureRmVMOSDisk更改了OS磁盘名称.然后,我删除了更改OS磁盘名称并成功的cmdlet.

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.

您可以参考创建虚拟机而不更改操作系统磁盘名称,如以下cmdlet:

You can refer to create the vm without changing the OS disk name like the following cmdlet:

$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -ManagedDiskId $disk.Id -CreateOption Attach -Windows 

我使用的整个powershell cmdlet:

The whole powershell cmdlet I used :

#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的可用性集(

----------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):

#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

这篇关于得到错误“不允许更改属性'osDisk.name'."使用Azure Powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆