将 Windows VM 移到其他 Azure 订阅或资源组Move a Windows VM to another Azure subscription or resource group

本文逐步说明如何在资源组或订阅之间移动 Windows 虚拟机 (VM)。This article walks you through how to move a Windows virtual machine (VM) between resource groups or subscriptions. 如果最初在个人订阅中创建了 VM,现在想要将其移到公司的订阅以继续工作,则在订阅之间移动 VM 可能很方便。Moving between subscriptions can be handy if you originally created a VM in a personal subscription and now want to move it to your company's subscription to continue your work. 无需停止 VM 来进行移动,并且该 VM 应在移动过程中继续运行。You do not need to stop the VM in order to move it and it should continue to run during the move.

重要

在移动过程中会创建新的资源 ID。New resource IDs are created as part of the move. 移动 VM 后,需要更新工具和脚本以使用新的资源 ID。After the VM has been moved, you will need to update your tools and scripts to use the new resource IDs.

使用 Azure 门户将 VM 移动到其他订阅Use the Azure portal to move a VM to a different subscription

可以使用 Azure 门户将 VM 及其关联的资源移动到其他订阅。You can move a VM and its associated resources to a different subscription by using the Azure portal.

  1. 打开 Azure 门户Open the Azure portal.
  2. 单击“浏览” > “资源组”,并选择包含要移动的 VM 的资源组。Click Browse > Resource groups and select the resource group containing the VM that you would like to move.
  3. 在资源组页的顶部,选择“移动”,然后选择“移动到另一个订阅” 。At the top of the page for the resource group, select Move and then select Move to another subscription. 此时将打开“移动资源” 页。The Move resources page opens.
  4. 选择要移动的每个资源。Select each of the resources to move. 大多数情况下,应移动列出的所有相关资源。In most cases, you should move all of the related resources that are listed.
  5. 选择要将 VM 移到其中的订阅Select the Subscription where you want the VM to be moved.
  6. 选择一个现有“资源组”,或者输入名称以创建新的资源组 。Select an existing Resource group, or enter a name to have a new resource group created.
  7. 完成后,选择你了解将创建新的资源 ID 并且移动后需要将新 ID 用于 VM,然后单击“确定” 。When you are done, select that you understand that new resource IDs will be created and that the new IDs will need to be used with the VM after it is moved, and then select OK.

使用 Azure 门户将 VM 移动到其他资源组Use the Azure portal to move a VM to another resource group

可以使用 Azure 门户将 VM 及其关联的资源移动到其他资源组。You can move a VM and its associated resources to another resource group by using the Azure portal.

  1. 打开 Azure 门户Open the Azure portal.
  2. 单击“浏览” > “虚拟机”,并从列表中选择要移动的 VM。Click Browse > Virtual machines and select the VM you would like to move from the list.
  3. 在 VM 页中,选择资源组标签旁边的“更改” 。In the page for the VM, next to the label for resource group, select Change. 此时将打开“移动资源” 页。The Move resources page opens.
  4. 选择要移动的每个资源。Select each of the resources to move. 大多数情况下,应移动列出的所有相关资源。In most cases, you should move all of the related resources that are listed.
  5. 选择一个现有“资源组”,或者输入名称以创建新的资源组 。Select an existing Resource group, or enter a name to have a new resource group created.
  6. 完成后,选择你了解将创建新的资源 ID 并且移动后需要将新 ID 用于 VM,然后单击“确定” 。When you are done, select that you understand that new resource IDs will be created and that the new IDs will need to be used with the VM after it is moved, and then select OK.

使用 PowerShell 移动 VMUse Powershell to move a VM

要将虚拟机移到其他资源组,需确保同时移动所有依赖资源。To move a virtual machine to another resource group, you need to make sure that you also move all of the dependent resources. 要获取每种资源的资源 ID 列表,请使用 Get-AzResource cmdlet。To get a list with the resource ID of each of these resources, use the Get-AzResource cmdlet.

 Get-AzResource -ResourceGroupName myResourceGroup | Format-table -wrap -Property ResourceId

可以使用上一命令的输出创建资源 ID 的逗号分隔列表,以使用 Move-AzResource 将每种资源移到目标。You can use the output of the previous command to create a comma-separated list of resource IDs to Move-AzResource to move each resource to the destination.

Move-AzResource -DestinationResourceGroupName "myDestinationResourceGroup" `
    -ResourceId <myResourceId,myResourceId,myResourceId>

要将资源移到其他订阅,请包含 -DestinationSubscriptionId 参数的值。To move the resources to different subscription, include the -DestinationSubscriptionId parameter.

Move-AzResource -DestinationSubscriptionId "<myDestinationSubscriptionID>" `
    -DestinationResourceGroupName "<myDestinationResourceGroup>" `
    -ResourceId <myResourceId,myResourceId,myResourceId>

当系统要求你确认是否要移动指定的资源时,请输入 Y 进行确认。When you are asked to confirm that you want to move the specified resources, enter Y to confirm.

后续步骤Next steps

可以在资源组和订阅之间移动许多不同类型的资源。You can move many different types of resources between resource groups and subscriptions. 有关详细信息,请参阅将资源移到新资源组或订阅For more information, see Move resources to a new resource group or subscription.