【问题标题】:Getting error "Changing property 'osDisk.name' is not allowed." with Azure Powershell Script出现错误“不允许更改属性 'osDisk.name'。”使用 Azure Powershell 脚本
【发布时间】:2018-02-04 19:24:08
【问题描述】:

我正在尝试将带有托管磁盘的现有 Azure VM 移动到现有可用性集中。但是,当我应用命令时:

New-AzureRmVM -ResourceGroupName $rg -Location $OriginalVM.Location -VM $NewVM -DisableBginfoExtension

我收到以下错误:

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

【问题讨论】:

    标签: azure powershell-3.0 azure-virtual-machine


    【解决方案1】:

    在 Azure 中,一旦将磁盘附加到 VM,就无法更改磁盘的名称。 OS 磁盘将获取您在创建 VM 期间提供的 VM 名称。您可以参考this link 了解更多详情。

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

    您可以参考创建 vm 而无需更改 OS 磁盘名称,如下 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
    

    【讨论】:

    • 韦恩,如果这对我有用,我将无法感谢你。现在去看看。
    • 嗨,Wayne,我正要查看你的脚本时发现了这个位于 gallery.technet.microsoft.com/… 的 .ps1 脚本。它似乎可以无缝运行,但是我不知道它是否支持托管磁盘。我已经问过脚本的所有者,我正在等待答复。你遇到过吗?
    • 嗨,Carltonp,在我的测试实验室中,我使用了托管磁盘。您可以在脚本中看到它。您可以尝试使用我的脚本。我确实成功地将带有托管磁盘的现有 Azure VM 移动到现有可用性集中。
    • 嗨,Carltonp。您是否使用了以下脚本:docs.microsoft.com/en-us/azure/virtual-machines/windows/…?本文档用于非托管磁盘。
    • 嗨 Wayne,那是我最初使用的脚本。不幸的是,它是为与非托管磁盘一起使用而设计的。顺便说一句,你的脚本就像一个魅力。干杯伙伴。
    【解决方案2】:

    对我来说,问题是我创建了一个托管磁盘(来自 Azure 门户),我选择了错误的操作系统导致我出现这种情况,我使用正确的操作系统重新创建了托管磁盘,然后部署工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-18
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多