'MultipleErrorsOccurred' 当我尝试将资源组移动到另一个订阅时显示错误消息
'MultipleErrorsOccurred' error message display when i am trying to move Resource Group to another subscription
我正在尝试将资源组从一个订阅移动到另一个订阅。我的资源组仅包含 SQL 服务器和 SQL 数据库。
注意:对于没有 SQL 服务器或数据库的资源组,脚本工作正常。
我可以从 Azure 门户手动执行此操作,但当我尝试 Powershell 时,它给出了错误消息。
Powershell:
$subscriptionID = "XXXX-XXXX-XXXX-XXXX-XXXX"
$destinationSubscriptionID = "YYYY-YYYY-YYYY-YYYY-YYYY"
Get-AzSubscription -SubscriptionId $subscriptionID -TenantId $tenant | Set-AzContext
$RG = "condecoteam2ent"
$Resource = Get-AzResource -ResourceGroupName $RG
Write-host "ResourceIds : " $Resource.ResourceId
Move-AzResource -ResourceId $Resource.ResourceId -DestinationSubscriptionId $destinationSubscriptionID -DestinationResourceGroupName $RG -Force
错误:
ResourceIds : /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/master /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/entmobiledb /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/minsyncdb /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/conintdb /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/minisyncload /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/conintdb_Copy /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/condecosyncqa3
MultipleErrorsOccurred : Multiple error occurred: BadRequest,BadRequest,BadReque
st,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.
CorrelationId: c02ad7c5-5b92-41b7-9d77-bce0261ed2a5
调试日志:
{
"code": "ResourceNotTopLevel",
"message": "Identifier '/subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server
/databases/minisyncload' is not a top level resource. Please include only the to
p-level resource for this child resource in the move request. A child resource w
ould be moved along with its associated top-level resource.\""
}
这是将资源移动到另一个资源组的方法
要将现有资源移动到另一个资源组或订阅,请使用 Move-AzureRmResource
命令。
下面是将一个资源移动到新订阅的命令
```
PS C:\> $resource = Get-AzureRmResource -ResourceName ExampleApp -ResourceGroupName OldRG
PS C:\> Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId $resource.ResourceId
```
对于多个资源新订阅
```
PS C:\> $webapp = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExampleSite
PS C:\> $plan = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExamplePlan
PS C:\> Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId ($webapp.ResourceId, $plan.ResourceId)
```
您甚至可以Refer了解更多详情
终于可以解决了
首先,脚本仅在移动具有 SQL 服务器和数据库的资源组时失败。
经过调查,我发现我们不需要移动SQL服务器的每个数据库。我们只需要移动资源组的顶级资源(即 SQL 服务器),它的数据库将随之自动移动。
所以现在我需要排除我从资源组中获取的数据库类型的资源 ID。
$Resource = Get-AzResource -ResourceGroupName $RG | Where-Object {$_.ResourceType -notcontains "Microsoft.Sql/servers/databases"}
现在我正在获取除数据库之外的所有资源 ID。所以现在我可以移动任何类型的资源组,而不管其内容如何。
我正在尝试将资源组从一个订阅移动到另一个订阅。我的资源组仅包含 SQL 服务器和 SQL 数据库。
注意:对于没有 SQL 服务器或数据库的资源组,脚本工作正常。
我可以从 Azure 门户手动执行此操作,但当我尝试 Powershell 时,它给出了错误消息。
Powershell:
$subscriptionID = "XXXX-XXXX-XXXX-XXXX-XXXX"
$destinationSubscriptionID = "YYYY-YYYY-YYYY-YYYY-YYYY"
Get-AzSubscription -SubscriptionId $subscriptionID -TenantId $tenant | Set-AzContext
$RG = "condecoteam2ent"
$Resource = Get-AzResource -ResourceGroupName $RG
Write-host "ResourceIds : " $Resource.ResourceId
Move-AzResource -ResourceId $Resource.ResourceId -DestinationSubscriptionId $destinationSubscriptionID -DestinationResourceGroupName $RG -Force
错误:
ResourceIds : /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/master /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/entmobiledb /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/minsyncdb /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/conintdb /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/minisyncload /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/conintdb_Copy /subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server/databases/condecosyncqa3
MultipleErrorsOccurred : Multiple error occurred: BadRequest,BadRequest,BadReque
st,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.
CorrelationId: c02ad7c5-5b92-41b7-9d77-bce0261ed2a5
调试日志:
{
"code": "ResourceNotTopLevel",
"message": "Identifier '/subscriptions/XXXX-XXXX-XXXX-XXXX-XXXX/resourceGroups/condecoteam2ent/providers/Microsoft.Sql/servers/qateam2server
/databases/minisyncload' is not a top level resource. Please include only the to
p-level resource for this child resource in the move request. A child resource w
ould be moved along with its associated top-level resource.\""
}
这是将资源移动到另一个资源组的方法
要将现有资源移动到另一个资源组或订阅,请使用 Move-AzureRmResource
命令。
下面是将一个资源移动到新订阅的命令
```
PS C:\> $resource = Get-AzureRmResource -ResourceName ExampleApp -ResourceGroupName OldRG
PS C:\> Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId $resource.ResourceId
```
对于多个资源新订阅
```
PS C:\> $webapp = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExampleSite
PS C:\> $plan = Get-AzureRmResource -ResourceGroupName OldRG -ResourceName ExamplePlan
PS C:\> Move-AzureRmResource -DestinationResourceGroupName NewRG -ResourceId ($webapp.ResourceId, $plan.ResourceId)
```
您甚至可以Refer了解更多详情
终于可以解决了
首先,脚本仅在移动具有 SQL 服务器和数据库的资源组时失败。
经过调查,我发现我们不需要移动SQL服务器的每个数据库。我们只需要移动资源组的顶级资源(即 SQL 服务器),它的数据库将随之自动移动。
所以现在我需要排除我从资源组中获取的数据库类型的资源 ID。
$Resource = Get-AzResource -ResourceGroupName $RG | Where-Object {$_.ResourceType -notcontains "Microsoft.Sql/servers/databases"}
现在我正在获取除数据库之外的所有资源 ID。所以现在我可以移动任何类型的资源组,而不管其内容如何。