为什么 Move-AzResource 无法移动同一资源组内具有依赖关系的资源?
Why does Move-AzResource fail to move resources with dependencies within the same resource group?
我正在尝试编写一个 powershell 脚本,自动将所有资源聚合到同一个资源组,但我遇到了停止执行 Move-AzResource 的错误。
$resources = Get-AzResource
#Skip already migrated resources:
$resources = $resources | Where-Object {$_.ResourceGroupName -ne "spMigrateResourceGroup"}
$groups = $resources | Group-Object ResourceGroupName
$groups = $groups.Name
$groups | ForEach-Object {
$group = $_
$groupResources = $resources | Where-Object ResourceGroupName -eq $group
$groupResourceIds = $groupResources.ResourceId
$response = Move-AzResource -DestinationResourceGroupName $resourceGroupTarget `
-ResourceId $groupResourceIds -Force -Verbose -Debug
Write-Host $response
}
由于 Move-AzResource 被限制在同一资源组内一次移动资源,我在同一资源组内获取 resourceId 并启动 Move-AzResource,但我遇到了如下错误:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id : e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
x-ms-correlation-request-id : e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
x-ms-routing-request-id : SOUTHCENTRALUS:20200331T165747Z:e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Tue, 31 Mar 2020 16:57:46 GMT
Body:
{
"error": {
"code": "MultipleErrorsOccurred",
"message": "Multiple error occurred: BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.",
"details": [
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo' is not a top level resource."
},
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/ },
{ Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows' is not a top level resource."
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/ },
{ Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo' is not a top level resource."
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/ },
{ Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC' is not a top level resource."
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/ },
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/
}
]
}
}
我相信当它说 "ResourceNotTopLevel" 时,它是说它是一种依赖关系,应该与控制它的顶级资源一起移动,就像带有数据库的数据库服务器一样。但我相当确定依赖项和依赖项打包在同一个资源组中,因此在 Move-AzResource 命令中提供。事实上,我可以使用资源组的 "Move" 功能在 Azure 门户上启动相同的命令,它成功地将组中的每个资源移动到目标资源组——这向我建议了移动所需的一切在资源组中。
所以我想我的问题有两个方面:为什么会发生这种情况(特别是因为它似乎在门户上工作),为什么 Move-AzResource 至少不继续移动它可以移动的资源? docs 建议该命令尽最大努力移动它可以移动的内容,但 Move-AzResource 似乎在尝试验证一些错误请求时停止。以下是循环一次迭代发送的资源:
Body:
{
"targetResourceGroup": "//resourceGroups/spMigrateResourceGroup",
"resources": [
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Storage/storageAccounts/stoae2arscache",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Storage/storageAccounts/frankcloudshellstorage",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/SPOCAE2S17W19",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/virtualNetworks/VNET-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/SQL-EXTERNAL",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/SQL2014SP3-EXTERNAL",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-VNG-VNET-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-SPOCAE2NST01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-RDG-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-EXTERNAL",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-DFS",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-ADS",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkSecurityGroups/NSG-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/spocae2nst01155",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2S17W19-01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDS02-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDG02-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDG01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2DFS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2BIS02-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2BIS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2ADS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/localNetworkGateways/LNG-VNET-SPOC-AWU",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/loadBalancers/ILB-SPOCAFCAE2-SSRS",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/loadBalancers/ILB-SPOCAFCAE2-SQL",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-SPOCAE2DFS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-SPOCAE2ADS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_TEMPDB_H",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_OSDISK",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_LOG_G",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_DATA_F",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_TEMPDB_H",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_OSDISK",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_LOG_G",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_DATA_F",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_TEMPDB_H",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_OSDISK",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_LOG_G",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_DATA_F",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDS02_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDG02_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDG01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2NST01_OsDisk_1_1e0ef5ca87c34a0d9283d37b3c531910",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2DFS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2DFS01_DFS_DISK_1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2BIS02_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2BIS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2ADS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-SQL-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-RDS-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-RDG-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-DFS-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-BIS-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-ADS-AE2"
]
}
注意:我从提供的错误中删除了订阅。
更新:这是扩展调试日志之前的错误消息:
Message : MultipleErrorsOccurred : Multiple error occurred: BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.
StackTrace : at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.EndProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
Exception : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses.ErrorResponseMessageException
InvocationInfo : {Move-AzResource}
Line : $response = Move-AzResource -DestinationResourceGroupName $resourceGroupTarget `
Position : At ...\aggregator.ps1:82 char:17
+ … $response = Move-AzResource -DestinationResourceGroupName $resourceGr …
+
从资源中删除所有 .../extensions/xxx
资源。即:
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC",
如果我们以这台机器(SPOCAE2S17W19
)和相关资源为例:
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19",
本例中的 "top level" 组是:
.../virtualMachines/SPOCAE2S17W19
其下的其他资源:
.../virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension
.../virtualMachines/SPOCAE2S17W19/extensions/joindomain
不是"top level groups"。
这些扩展将自动与主要 "top level" 组一起移动,例如.../virtualMachines/SPOCAE2S17W19
。
事实证明,您可以通过以下方式防止这种情况发生:
$topResources = $resources | Where-Object { -not $_.ParentResource}
从this中找到。
我正在尝试编写一个 powershell 脚本,自动将所有资源聚合到同一个资源组,但我遇到了停止执行 Move-AzResource 的错误。
$resources = Get-AzResource
#Skip already migrated resources:
$resources = $resources | Where-Object {$_.ResourceGroupName -ne "spMigrateResourceGroup"}
$groups = $resources | Group-Object ResourceGroupName
$groups = $groups.Name
$groups | ForEach-Object {
$group = $_
$groupResources = $resources | Where-Object ResourceGroupName -eq $group
$groupResourceIds = $groupResources.ResourceId
$response = Move-AzResource -DestinationResourceGroupName $resourceGroupTarget `
-ResourceId $groupResourceIds -Force -Verbose -Debug
Write-Host $response
}
由于 Move-AzResource 被限制在同一资源组内一次移动资源,我在同一资源组内获取 resourceId 并启动 Move-AzResource,但我遇到了如下错误:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-cache
Pragma : no-cache
x-ms-failure-cause : gateway
x-ms-ratelimit-remaining-subscription-writes: 1199
x-ms-request-id : e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
x-ms-correlation-request-id : e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
x-ms-routing-request-id : SOUTHCENTRALUS:20200331T165747Z:e0f0f5e3-faaf-44ad-b3e4-61e51ad89a84
Strict-Transport-Security : max-age=31536000; includeSubDomains
X-Content-Type-Options : nosniff
Date : Tue, 31 Mar 2020 16:57:46 GMT
Body:
{
"error": {
"code": "MultipleErrorsOccurred",
"message": "Multiple error occurred: BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.",
"details": [
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows' is not a top level resource."
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo' is not a top level resource."
},
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/ },
{ Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows' is not a top level resource."
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/ },
{ Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo' is not a top level resource."
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/ },
{ Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC' is not a top level resource."
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/ },
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/rg-spoc-ae2/providers/
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/
},
{
"code": "ResourceNotTopLevel",
"message": "Identifier '//resourceGroups/RG-SPOC-AE2/providers/
}
]
}
}
我相信当它说 "ResourceNotTopLevel" 时,它是说它是一种依赖关系,应该与控制它的顶级资源一起移动,就像带有数据库的数据库服务器一样。但我相当确定依赖项和依赖项打包在同一个资源组中,因此在 Move-AzResource 命令中提供。事实上,我可以使用资源组的 "Move" 功能在 Azure 门户上启动相同的命令,它成功地将组中的每个资源移动到目标资源组——这向我建议了移动所需的一切在资源组中。
所以我想我的问题有两个方面:为什么会发生这种情况(特别是因为它似乎在门户上工作),为什么 Move-AzResource 至少不继续移动它可以移动的资源? docs 建议该命令尽最大努力移动它可以移动的内容,但 Move-AzResource 似乎在尝试验证一些错误请求时停止。以下是循环一次迭代发送的资源:
Body:
{
"targetResourceGroup": "//resourceGroups/spMigrateResourceGroup",
"resources": [
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Storage/storageAccounts/stoae2arscache",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Storage/storageAccounts/frankcloudshellstorage",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/SPOCAE2S17W19",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/virtualNetworks/VNET-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/SQL-EXTERNAL",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/SQL2014SP3-EXTERNAL",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-VNG-VNET-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-SPOCAE2NST01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-RDG-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-EXTERNAL",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-DFS",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/publicIPAddresses/PIP-ADS",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkSecurityGroups/NSG-SPOC-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/spocae2nst01155",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2S17W19-01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDS02-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDG02-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2RDG01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2DFS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2BIS02-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2BIS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/networkInterfaces/NIC-SPOCAE2ADS01-1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/localNetworkGateways/LNG-VNET-SPOC-AWU",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/loadBalancers/ILB-SPOCAFCAE2-SSRS",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Network/loadBalancers/ILB-SPOCAFCAE2-SQL",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-SPOCAE2DFS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.DevTestLab/schedules/shutdown-computevm-SPOCAE2ADS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_TEMPDB_H",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_OSDISK",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_LOG_G",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL_DATA_F",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_TEMPDB_H",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_OSDISK",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_LOG_G",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SQL2014SP3_DATA_F",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_TEMPDB_H",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_OSDISK",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_LOG_G",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2S17W19_DATA_F",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDS02_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDG02_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2RDG01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2NST01_OsDisk_1_1e0ef5ca87c34a0d9283d37b3c531910",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2DFS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2DFS01_DFS_DISK_1",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2BIS02_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2BIS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/disks/SPOCAE2ADS01_OSDISK.vhd",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-SQL-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-RDS-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-RDG-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-DFS-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-BIS-AE2",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/availabilitySets/AS-SPOC-ADS-AE2"
]
}
注意:我从提供的错误中删除了订阅。
更新:这是扩展调试日志之前的错误消息:
Message : MultipleErrorsOccurred : Multiple error occurred: BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest,BadRequest. Please see details.
StackTrace : at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.HandleException(ExceptionDispatchInfo capturedException)
at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.EndProcessing()
at System.Management.Automation.CommandProcessorBase.Complete()
Exception : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses.ErrorResponseMessageException
InvocationInfo : {Move-AzResource}
Line : $response = Move-AzResource -DestinationResourceGroupName $resourceGroupTarget `
Position : At ...\aggregator.ps1:82 char:17
+ … $response = Move-AzResource -DestinationResourceGroupName $resourceGr …
+
从资源中删除所有 .../extensions/xxx
资源。即:
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG02/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2RDG01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2DFS01/extensions/BGInfo",
"//resourceGroups/rg-spoc-ae2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/SiteRecovery-Windows",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2BIS01/extensions/BGInfo",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2ADS01/extensions/Microsoft.Powershell.DSC",
如果我们以这台机器(SPOCAE2S17W19
)和相关资源为例:
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19/extensions/joindomain",
"//resourceGroups/RG-SPOC-AE2/providers/Microsoft.Compute/virtualMachines/SPOCAE2S17W19",
本例中的 "top level" 组是:
.../virtualMachines/SPOCAE2S17W19
其下的其他资源:
.../virtualMachines/SPOCAE2S17W19/extensions/SqlIaasExtension
.../virtualMachines/SPOCAE2S17W19/extensions/joindomain
不是"top level groups"。
这些扩展将自动与主要 "top level" 组一起移动,例如.../virtualMachines/SPOCAE2S17W19
。
事实证明,您可以通过以下方式防止这种情况发生:
$topResources = $resources | Where-Object { -not $_.ParentResource}
从this中找到。