I have a container with locked immutable policy:
There is already no any blobs within this container. I tried to delete this container with below powershell command:
Remove-AzStorageContainer -Name $containerName -Force
But got below error:
The requested operation is not allowed as the container has a locked immutability policy. HTTP Status Code: 409
However, I can delete this container from azure portal successfully.
My question is, why I can delete from portal but cannot using powershell? Is there a way to automatic remove the container with locked immutable policy?
3
Answers
References:
Storage accounts can be interacted with in two different ways – via the data plane REST API (ie. myaccount.blob.core.windows.net) and through ARM (ie. management.azure.com) via the Storage Resource Provider.
The Powershell cmdlets in the form of xxx-AzStoragexxx use data plane. The Powershell cmdlets in the form of xxx-AzRmStoragexxx use ARM.
Managing immutable policies must be done through ARM rather than through the data plane. When interacting with storage accounts via the portal you are using ARM so it works as you would expect. With Powershell, in order to delete a container that has an immutable policy, you must use the AzRmStorage cmdlets.
To programmatically delete a container with an immutable policy you first have to delete all blobs in the container, then use one of the following:
Remove-AzRmStorageContainer
az storage container-rm delete
Powershell can also delete container with management plane cmdlet:
login Azure account, not needed if you have done so before
Remove container
You may also refer to the suggestion mentioned in this thread and let me know the status of the issue
Note: Please make sure you are using the control plane cmdlet “Remove-AzRmStorageContainer” to delete the share .
If still fail, please add “-debug” and share the debug log to investigate. (hide if any credential.)