重置远程桌面服务或其在 Windows VM 中的管理员密码Reset Remote Desktop Services or its administrator password in a Windows VM

如果无法连接到 Windows 虚拟机 (VM),可以重置本地管理员密码或远程桌面服务配置(Windows 域控制器不支持此操作)。If you can't connect to a Windows virtual machine (VM), you can reset your local administrator password or reset the Remote Desktop Services configuration (not supported on Windows domain controllers). 若要重置密码,可以使用 Azure 门户或 Azure PowerShell 中的 VM 访问扩展。To reset the password, use either the Azure portal or the VM Access extension in Azure PowerShell. 登录到 VM 后,重置该本地管理员的密码。After you've signed in to the VM, reset the password for that local administrator.
如果使用 PowerShell,请务必安装和配置最新的 PowerShell 模块,并登录到 Azure 订阅。If you're using PowerShell, make sure that you have the latest PowerShell module installed and configured and are signed in to your Azure subscription. 也可以对使用经典部署模型创建的 VM 执行这些步骤You can also perform these steps for VMs created with the classic deployment model.

可按以下方式重置远程桌面服务和凭据:You can reset Remote Desktop Services and credentials in the following ways:

使用 Azure 门户重置Reset by using the Azure portal

首先,登录到 Azure 门户,然后在左侧菜单中选择“虚拟机” 。First, sign in to the Azure portal and then select Virtual machines on the left menu.

重置本地管理员帐户密码Reset the local administrator account password

  1. 选择 Windows VM,然后在“支持 + 故障排除”下选择“重置密码”。 Select your Windows VM and then select Reset password under Support + Troubleshooting. 此时会显示“重置密码”窗口。 The Reset password window is displayed.

  2. 选择“重置密码”,输入用户名和密码,然后选择“更新”。 Select Reset password, enter a username and a password, and then select Update.

  3. 尝试重新连接到 VM。Try connecting to your VM again.

重置远程桌面服务配置Reset the Remote Desktop Services configuration

此过程将启用 VM 中的远程桌面服务,并为默认 RDP 端口 3389 创建防火墙规则。This process will enable Remote Desktop service in the VM, and create a firewall rule for the default RDP port 3389.

  1. 选择 Windows VM,然后在“支持 + 故障排除”下选择“重置密码”。 Select your Windows VM and then select Reset password under Support + Troubleshooting. 此时会显示“重置密码”窗口。 The Reset password window is displayed.

  2. 依次选择“仅重置配置”、“更新”。 Select Reset configuration only and then select Update.

  3. 尝试重新连接到 VM。Try connecting to your VM again.

使用 VMAccess 扩展和 PowerShell 重置Reset by using the VMAccess extension and PowerShell

首先,请确保已安装并配置最新的 PowerShell 模块,然后使用 Connect-AzAccount -Environment AzureChinaCloud cmdlet 登录到 Azure 订阅。First, make sure that you have the latest PowerShell module installed and configured and are signed in to your Azure subscription by using the Connect-AzAccount -Environment AzureChinaCloud cmdlet.

重置本地管理员帐户密码Reset the local administrator account password

  • 使用 Set-AzVMAccessExtension PowerShell cmdlet 重置管理员密码或用户名。Reset the administrator password or user name with the Set-AzVMAccessExtension PowerShell cmdlet. typeHandlerVersion 设置必须为 2.0 或以上,因为版本 1 已弃用。The typeHandlerVersion setting must be 2.0 or greater, because version 1 is deprecated.

    $SubID = "<SUBSCRIPTION ID>" 
    $RgName = "<RESOURCE GROUP NAME>" 
    $VmName = "<VM NAME>" 
    $Location = "<LOCATION>" 
    
    Connect-AzAccount -Environment AzureChinaCloud 
    Select-AzSubscription -SubscriptionId $SubID 
    Set-AzVMAccessExtension -ResourceGroupName $RgName -Location $Location -VMName $VmName -Credential (get-credential) -typeHandlerVersion "2.0" -Name VMAccessAgent 
    

    备注

    如果在 VM 上输入不同于当前本地管理员帐户的名称,则 VMAccess 扩展使用该名称添加本地管理员帐户,将指定密码分配给该帐户。If you enter a different name than the current local administrator account on your VM, the VMAccess extension will add a local administrator account with that name, and assign your specified password to that account. 如果 VM 上的本地管理员帐户存在,则 VMAccess 扩展将重置密码。If the local administrator account on your VM exists, the VMAccess extension will reset the password. 如果该帐户已禁用,则 VMAccess 扩展会将其启用。If the account is disabled, the VMAccess extension will enable it.

重置远程桌面服务配置Reset the Remote Desktop Services configuration

  1. 使用 Set-AzVMAccessExtension PowerShell cmdlet 重置对 VM 的远程访问。Reset remote access to your VM with the Set-AzVMAccessExtension PowerShell cmdlet. 以下示例在名为 myResourceGroup 的资源组中名为 myVM 的 VM 上重置名为 myVMAccess 的访问扩展:The following example resets the access extension named myVMAccess on the VM named myVM in the myResourceGroup resource group:

    Set-AzVMAccessExtension -ResourceGroupName "myResoureGroup" -VMName "myVM" -Name "myVMAccess" -Location ChinaNorth -typeHandlerVersion "2.0" -ForceRerun
    

    提示

    无论何时,一个 VM 只能有一个 VM 访问代理。At any point, a VM can have only a single VM access agent. 若要设置 VM 访问代理属性,请使用 -ForceRerun 选项。To set the VM access agent properties, use the -ForceRerun option. 使用 -ForceRerun 时,请确保对 VM 访问代理使用在前面的任何命令中可能用过的相同名称。When you use -ForceRerun, ensure you use the same name for the VM access agent that you might have used in any previous commands.

  2. 如果仍然无法远程连接到虚拟机,请参阅排查基于 Windows 的 Azure 虚拟机的远程桌面连接问题If you still can't connect remotely to your virtual machine, see Troubleshoot Remote Desktop connections to a Windows-based Azure virtual machine. 如果与 Windows 域控制器的连接断开,则需要从域控制器备份中还原。If you lose the connection to the Windows domain controller, you will need to restore it from a domain controller backup.

后续步骤Next steps