无法让 Move-AzureResource 工作

Can't get Move-AzureResource working

我正在尝试将我的一些资源(Azure Web 应用程序、Azure SQL、Redis 缓存)从一个资源组移动到另一个资源组。我正在使用 Azure 资源管理器 PowerShell cmdlet。

这是我试过的方法:

PS C:\> Move-AzureResource -DestinationResourceGroupName NewResourceGroup -ResourceId "/subscriptions/someguid/resourceGroups/Default-Web-WestEurope/providers/Microsoft.Web/sites/somesite"

或:

PS C:\> Get-AzureResource -ResourceName somesite | Move-AzureResource -DestinationResourceGroupName NewResourceGroup

或者: 只需 Move-AzureResource,按回车键并一一提供参数。

None 的命令似乎有效。他们只是什么都不做。没有错误,没有输出。 当我将调试首选项更改为 $DebugPreference = "Continue" 时,我只得到以下内容:

DEBUG: 12:16:06 - MoveAzureResourceCommand begin processing with ParameterSet '__AllParameterSets'.
DEBUG: 12:16:06 - using account id 'my@account.tld'...

请注意,我可以创建新资源组 (New-AzureResourceGroup)、列出资源组 (Get-AzureResourceGroup)、列出资源 (Get-AzureResource) 等。

注意:您必须先调用 Switch-AzureMode AzureResourceManager,然后才能使用这些 cmdlet。身份验证由 Add-AzureAccount.

完成

我参考的文章:

阅读这篇文章azure forum 看起来他们已经实施了 cmdlet,但并非所有资源都支持移动。

We have released a new powershell cmdlet to move resources across resource groups. Not all resources have support yet, but the "main" ones do like hosted services, virtual machines & storage accounts.

回顾一下我所遵循的示例,它只使用了 VM。因此,基于此,我认为网站还不受支持。对于不受支持的资源没有返回错误或警告这一事实有点糟糕。

虽然目前并非所有资源都受支持,但我知道当前版本 - 0.9.1 - 确实有一个错误,这意味着即使是受支持的资源也可能不会随着问题作者所看到的症状而移动。我知道这是在下一个版本中进行的,但在过渡期间(作为临时工作),2 个版本之前的 powershell cmdlet 版本应该可以正常工作。 https://github.com/Azure/azure-powershell/releases

仅供参考。要使用 Move-AzureResourceGroup 移动 VM,您需要同时移动包含的云服务及其所有 VM。例如:

Get-AzureResource -ResourceGroupName OriginalResourceGroup | where { $_.ResourceType -match 'Microsoft.ClassicCompute' } | Move-AzureResource -DestinationResourceGroupName NewResourceGroup

默认情况下,云服务中的资源被放在与云服务的 DNS 名称同名的资源组中。

原问题已在 0.9.4 release 中修复。我刚刚试过了,效果很好。

出于某种原因,Azure PowerShell 版本 1.0 无法将 Web 应用程序从一个资源组转移到另一个资源组。如果您遵循以下说明,您将能够通过 powershell 移动网络应用程序。

下载 Azure PowerShell 版本 1。以下说明仅适用于此版本。按顺序键入以下命令。

1) **Login-AzureRmAccount** (a login window will pop up asking for your azure credentials, type them in)
2) **Get-AzureRmResource -ResourceGroupName "NameOfResourceGroup" -ResourceName "WebAppName"** (if you are moving over a website, you will see 2 files, you need the one that is a resource type of Microsoft.Web/sites)
3) **Get-AzureRmResource -ResourceGroupName "NameOfResourceGroup" -ResourceName "WebAppName" -ResourceType "Microsoft.Web/sites"**
4) Assign value 3 to a variable of your name choice. I Chose $a, so **$a = Get-AzureRmResource -ResourceGroupName "NameOfResourceGroup" -ResourceName "WebAppName" -ResourceType "Microsoft.Web/sites"**
5) **Move-AzureRmResource -DestinationResourceGroup "DestinationResourceGroup" -ResourceId $a.ResourceId**
6) It will ask you if you are sure type "Y" and hit enter.