Table of Contents
‘The scope cannot perform delete operation because following scope(s) are locked‘
The tutorial works for all Azure resources that have a lock. I ran into it while working on Azure Automation runbooks, where I try to delete runbooks, so I’ve used this in my screenshots and error messages.
There is a lock on your Azure resources… ‘to protect your infrastructure’
Yes, there is a lock on your Azure Resources.
This can be done at the subscription level, Resource Group, resource, or a resource within a resource, such as an Azure Automation runbook.
When you apply a lock at a parent scope, all resources within that scope inherit the same lock. Even resources you add later inherit the same parent lock. The most restrictive lock in the inheritance takes precedence.
Source: Protect your Azure resources with a lock – Azure Resource Manager
If you go to the relevant resource and then search for Locks in the menu, you can see whether there is a Lock on the resource and at what level it is applied, as in the screenshot below.

Please remove the lock and try again.. Error code: ScopeLocked..
By removing it you can adjust resources again. Think carefully about why it exists and whether it’s a logical step to remove it.
The personal story you can skip as of how I got this error…
I have been on leave for 4 months and I am immediately told by colleagues that a pipeline in which runbooks are created in an Azure Automation environment does not work.
It worked before, so what happened in those 4 months?
What we do in the pipeline, is first remove the old runbook from the environment and then recreate the runbook.
We do this this way, because we are currently creating runbooks with PS version 7, which is a preview version within Azure Automation. There are or were still bugs when updating a runbook, so we have chosen to recreate the runbooks.
The error messages via PowerShell and Azure Automation when you try to delete a runbook
For the tutorial itself I generated the error messages in PowerShell & the Azure portal.
PowerShell
Something went wrong removing RUNBOOK in AUTOMATIONACCOUNTNAME: The scope cannot perform delete operation because
following scope(s) are locked:
Please remove the lock and try again
The Azure portal
In the Azure Automation portal:

As a notification:

The text from the notification:
An error occurred while deleting the runbook named 'BAS01'. Error details: The scope cannot perform delete operation because following scope(s) are locked: Please remove the lock and try again.. Error code: ScopeLocked..