【问题标题】:Can’t RDP a VM created via attaching an unmanaged windows vhd (PowerShell and ARM Template)无法对通过附加非托管 Windows vhd(PowerShell 和 ARM 模板)创建的 VM 进行 RDP
【发布时间】:2020-08-24 07:39:55
【问题描述】:

从最近几天开始,我遇到了一种情况,即我无法对通过附加非托管 Windows vhd 创建的 Azure VM 进行 RDP。 我解释了执行的步骤,

  1. 从 azure VM msdn 创建了一个非托管 VM 映像 (vhd)

    一个。使用非托管 OS 磁盘创建了 Azure VM (Windows Server 2016)。

    b.使用 Sysprep msdn 通用化 VM。

    c。解除分配 VM 并使用 PowerShell 将状态设置为泛化。

Stop-AzureRmVM -ResourceGroupName '[RG]' -Name '[vhdtest]' 

Set-AzureRmVM -ResourceGroupName '[RG]' -Name '[vhdtest]' –Generalized

Save-AzureRmVMImage -ResourceGroupName '[RG]' -Name '[vhdtest]' `
    -DestinationContainerName 'newvhds' -VHDNamePrefix 'new3'

我可以看到新的 VHD 已复制到系统 blob 容器中。

  1. 通过使用 PowerShell 附加在步骤 1 中创建的 VHD,使用非托管磁盘创建了一个 VM。 执行以下步骤或 PowerShell 命令来创建 VM 并附加 VHD,
# created Subnet
$rgName = "Technovate2020_Logicators-RG"
$subnetName = "mySubNet-attach"
$singleSubnet = New-AzureRMVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24

# created virtual Network with assignig Subnet
$location = "CentralUS"
$vnetName = "myVnetName-attach"
$vnet = New-AzureRMVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Location $location `
    -AddressPrefix 10.0.0.0/16 -Subnet $singleSubnet


# created Network Security Group rule to enable RDP
$nsgName = "myNsg-attach"
$rdpRule = New-AzureRMNetworkSecurityRuleConfig -Name myRdpRule -Description "Allow RDP" `
    -Access Allow -Protocol Tcp -Direction Inbound -Priority 110 `
    -SourceAddressPrefix Internet -SourcePortRange * `
    -DestinationAddressPrefix * -DestinationPortRange 3389


# created Network Security Group and assiging rules
$nsg = New-AzureRMNetworkSecurityGroup -ResourceGroupName $rgName -Location $location `
    -Name $nsgName -SecurityRules $rdpRule


# created Public IP
$ipName = "myIP-attach"
$pip = New-AzureRMPublicIpAddress -Name $ipName -ResourceGroupName $rgName -Location $location `
    -AllocationMethod Dynamic


# created Network Interface Card
$nicName = "myNicName-attach"
$nic = New-AzureRMNetworkInterface -Name $nicName -ResourceGroupName $rgName `
 -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $nsg.Id


# created VM Configurations
$vmName = "myVM-attach"
$vmConfig = New-AzureRMVMConfig -VMName $vmName -VMSize "Standard_D4s_v3"
# Assign NIC
$vm = Add-AzureRMVMNetworkInterface -VM $vmConfig -Id $nic.Id


# Unmanaged OS Disk to attach (already copied the vhd from 'system' container to 'vhds')
$osDiskUri = "https://technovate2020logicators.blob.core.windows.net/vhds/new3-osDisk.vhd"


# assigning OS Disk using 'attach' option
$osDiskName = $vmName + "osDisk"
$vm = Set-AzureRMVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption attach -Windows


#Create the VM
New-AzureRMVM -ResourceGroupName $rgName -Location $location -VM $vm 

已创建具有非托管 OS 磁盘的 VM。 问题/问题:无法 RDP 虚拟机。

附加信息:- 如果我使用非托管 OS 磁盘创建相同的 VM,但使用 fromImage 选项而不是 attach,则允许我对 VM 进行 RDP。

【问题讨论】:

    标签: azure powershell


    【解决方案1】:

    您为执行此过程而运行的命令属于已弃用的 powershell 模块 AzureRm。我建议您首先卸载 azurerm powershell 模块并安装新的 az powershell 模块(这些模块不能在同一台机器上共存),更新您的脚本以使用新的 powershell 模块 cmdlet,然后看看它如何为您工作。

    【讨论】:

    • 感谢威廉姆斯的回复和建议。
    • 我尝试了以下操作以使 vhd 满足我的要求,1- 使用非托管操作系统磁盘创建 VM。 (之前也是这样做的。) 2- 为了从中创建 VHD,只需删除 VM 和其他相关资源(例如,公共 IP、nic、nsg 等) 3- 将留下 vhd虚拟机。 4-从步骤 3 创建附加 vhd 的 VM,它可以工作(使用 ARM 模板尝试)。基本上不需要执行docs.microsoft.com/en-us/azure/virtual-machines/windows/…提到的步骤
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多