1

I am trying to execute a PowerShell script that will sequentially remove Azure Resources from a resource group using a .ps1 file, and have isolated an error I am getting to whenever I try to remove the Microsoft.Insights/components resource using the command:

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

The error I'm getting after running this once is as follows:

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

From what I can tell, there seems to be some kind of "pre-condition" that needs to be met before you can delete it... but the weirdest part is that if I execute the same command again, I don't get an error and the resource is successfully deleted...

Is there any reason why this would fail once, but then succeed in being deleted after executing again?

LillaTheHun
  • 131
  • 1
  • 13

1 Answers1

1

This is because the Insights is used by your Web APP. Please refer to this link. When you enable client side monitoring, you will get the error log. I test in my lab, I get the same result with you.

enter image description here

enter image description here

If you want to avoid this error log. Please refer to the following steps:

1.Delete APPINSIGHTS_JAVASCRIPT_ENABLED key.

2.Restart your app.

3.Delete Insights.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
  • Thank you! That totally makes sense. Do you know if there is an easy way to do this in PowerShell? My goal is to be able to automate this process, so it would be valuable if I could just add this to my resource removal script. Thanks again! – LillaTheHun Jul 19 '17 at 02:58
  • @LillaTheHun You could check this [link](https://codehollow.com/2016/06/automatically-set-azure-app-settings/). Set `APPINSIGHTS_JAVASCRIPT_ENABLED` false or delete it and restart your app. – Shui shengbao Jul 19 '17 at 06:16
  • After attempting to duplicate your suggestion, I noticed that in my Web App there wasn't an APPINSIGHTS_JAVASCRIPT_ENABLED key for me to delete, and the error still remained -- Could there be another reason for the error? – LillaTheHun Jul 19 '17 at 18:00
  • @LillaTheHun According to the error log, it seems Insights is used with some resources. If possible, could you share how do you create you web app and Insights. Also, I will test in my lab and find the reason. – Shui shengbao Jul 20 '17 at 01:14
  • @LillaTheHun Do you try delete your webapp and web service plan firstly, then delete Insights. – Shui shengbao Jul 20 '17 at 01:53