Script Sample - Removing Locks from Azure Resources@20aman Dec 16, 2018
In one of the earlier posts, we discussed the benefits of using locks and why you should apply these (to avoid accidental deletion) to any critical and important resources in Azure. We also saw a script sample to apply the locks on all key resources in your environment. The same can be reviewed again here: Apply Locks on Various Azure Resources.
Now once you have locks, you won't be able to remove the resources or remove configurations from them. To be able to remove configurations or to remove the resources itself you will need to remove the locks. You can do so in an automated fashion by using this script sample.
Script Requirements and Workings
The script does not have any specific requirements.
The script sample removes lock from all Azure Route Tables, but the same concept can be applied to any type of resource. It first fetches the Route Tables by using the below command:
$routeTables = Get-AzureRmRouteTable
Then it simply removes the lock by using the below command:
Remove-AzureRmResourceLock -LockName DoNotDelete -ResourceGroupName $routeTable.ResourceGroupName -ResourceName $routeTable.Name -ResourceType $routeTable.Type -Force
Location of the Script
You can find this script in GitHub at this location: Remove-Locks.ps1