为什么在尝试删除 Microsoft.Insights/components 资源时出现错误?

Why am I getting an error when trying to remove a Microsoft.Insights/components resource?

我正在尝试执行一个 PowerShell 脚本,该脚本将使用 .ps1 文件从资源组中按顺序删除 Azure 资源,并隔离了每当我尝试删除 Microsoft. Insights/components 资源使用命令:

Remove-AzureRmResource -ResourceId "/subscriptions/e41d3122-bbd8-48dc-a212-0337139671cc/resourceGroups/TestRG/providers/Microsoft.Insights/components/WA-Stag-API-EMEA-zgqmgcwnigknu"

这一次运行后出现的错误如下:

Remove-AzureRmResource : {"code":"Message: {\"Errors\":[\"One of the specified pre-condition is not met\"]}","message":"Message: {\"Errors\":[\"One of the specified pre-condition is not met\"]}\r\nActivityId: 845b19fa-b6b4-4952-9b62-75bfc6e98646, Request URI: /apps/1921ec42-1c88-4fdd-8d6c-78646cba4b15/services/a32b484a-6ee1-4ad7-ab43-4e9 d57bb0b81/partitions/fab8c193-3ec3-45e8-b7a6-0e21d1e071da/replicas/131441657816991616p","innererror":{"diagnosticcontext":"597ea546-7625-474d-b27f-560a1140a652","time":"2017- 07-18T19:41:25.3734216Z"}} At line:1 char:1 + Remove-AzureRmResource -ResourceId "/subscriptions/e41d3122-bbd8-48dc ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Remove-AzureRmResource], ErrorResponseMessageException + FullyQualifiedErrorId : Conflict,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet

据我所知,似乎需要满足某种 "pre-condition" 才能删除它...但最奇怪的是,如果我再次执行相同的命令,我没有收到错误消息,资源已成功删除...

请问是什么原因导致一次执行失败,再次执行成功又被删除?

这是因为您的Web APP 使用了Insights。请参考这个link。当您启用客户端监控时,您将获得错误日志。我在实验室测试,结果和你一样。

如果你想避免这个错误日志。请参考以下步骤:

1.Delete APPINSIGHTS_JAVASCRIPT_ENABLED 键。

2.Restart 您的应用。

3.Delete 见解。