The other day I was removing some diagnostic settings from a few Azure resources. I was able to remove most of them via the Azure portal, but one just wouldn’t let go. No matter how many times I tried deleting it, it still remained.
After a quick googling it turns out that I wasn’t the only one who had experienced this problem. Turns out you need to fix this via a CLI.
This is my solution to fixing this issue, using Powershell. If you already haven’t, make sure that you have Azure CLI installed on your machine before getting started.
Before we do anything we need to retrieve the ID of the resource to which the diagnostic setting is applied. There are multiple ways to do this, but the easiest one is probably to navigate to the resource in the Azure Portal. Then click “JSON View” in the top right corner of the Overview blade.
Among other things, the resource ID will now be displayed. Your resource ID will probably look a little something like above.
We will also need the ID of our Azure subscription. This can be retrieved by navigating to the subscriptions blade in the Azure portal.
And finally we need the name of the diagnostic setting we’re about to remove. This can be retrieved from the “Diagnostic settings” blade in the corresponding resource.
Save the resource ID, subscription ID and diagnostic setting name. We will need them later in the process.
Start Powershell and run the following command:
You will now be prompted to login to your organization or tenant. Log in.
To set the context to the subscription in which we are removing the diagnostic setting, enter the following command. Replace the x with your subscription ID that we retrieved in step 1.
To remove the diagnostic setting, run the following command. Replace MyResourceID and MyDiagnosticSetting with your corresponding data from step 1. The command flags specify which diagnostic setting that should be removed from which resource.
If all went well you should now see something like this in your Powershell window:
The diagnostic setting should now also be gone in the Azure portal.