Skip to content

Ulysses Neves

Microsoft Entra ID, authentication, and hybrid identity troubleshooting.

Menu
  • Home
  • Microsoft Azure
  • Microsoft AD FS
  • Microsoft 365
  • Contact
  • Troubleshooting Index
Menu

Azure Resource Locks

Posted on July 29, 2019

Hello everyone, in the last post we explained how to create and remove resource groups using PowerShell and the Azure CLI. If you haven’t read it yet, check out this link.

In this post, we’ll explain how to use Azure resource lock to protect resources and resource groups in Azure from accidental removal in Azure.

What is Resource Lock?

Azure Resource Lock is designed to protect resource groups and resources from accidental removal, blocking changes in two ways: “CanNotDelete” and “ReadOnly“.

Creating a Lock on a resource group in the Azure Portal

Below, we’ll show how to create a lock on a resource group using the Azure portal:

In the Azure portal, access the Resource groups menu.

Click the Resource group and navigate the menu on the left until you find the Locks button.

Click the Add button to add a lock to the selected resource group.

To illustrate, I’m creating a Read-Only type Lock named “Rg-ReadOnly”.

Now let’s try to delete the resource group “rsg-lab-rgl” that we just protected with the Lock.

Click “Overview” and “Delete resource group“.

When you try to delete a resource group that’s protected by a lock, a message is displayed informing you of the protection, and clicking the message redirects you to the lock that’s protecting that resource from removal.

Removing a lock using the portal

To unblock removal of a resource or resource group using the portal, select the resource for which you want to remove the protection, click the menu to the right of the lock, and then Delete.

After removing the lock from the resource group, it will be possible to remove the item that was previously protected.

Creating locks through PowerShell

Now let’s create a resource group lock using PowerShell. With the command below, I’m creating a lock named Lock-ps for the resource group rg-lab-locks with a brief description of the reason for the protection in the notes field (optional).

Note: If you don’t have the Azure module for PowerShell yet, check out this link where I explain how to install the Azure module in PowerShell and connect to Azure.

Open PowerShell, connect to Azure, and run the command below:

New-AzResourceLock -LockLevel CanNotDelete -LockNotes "Lock pelo powershell" -LockName "Lock-ps" -ResourceGroupName "rg-lab-locks"

Syntax: New-AzResourceLock -LockLevel “CanNotDelete or ReadOnly” -LockNotes “description note” -LockName “lock name” -ResourceGroupName “resource group name”

Let’s create a lock on the storage resource I provisioned to illustrate this activity. I’ll run the command below to create a lock that blocks deletion of this resource:

New-AzResourceLock -LockLevel CanNotDelete -LockNotes "lock de recurso em ps" -LockName "storslock" -ResourceName "stolablock" -ResourceType "Microsoft.Storage/storageAccounts" -ResourceGroupName "rg-lab-locks"

Syntax: New-AzResourceLock -LockLevel “CanNotDelete or ReadOnly” -LockNotes “description note” -LockName “lock name” -ResourceName “resource name”

When I try to remove the storage resource that was created, I receive a message that it’s not possible to remove it because there’s a lock protecting that resource from removal.

For more information about resource lock command options in Azure, check out this link.

Identifying existing locks

To identify the existing locks in the subscription, run the command “get-azresourcelock”.

Removing locks using PowerShell

To remove a lock using PowerShell, we’ll collect the Lockid and store it in a variable called $lockid, using the command below:

$lockid = (Get-AzResourceLock -ResourceGroupName rg-lab-locks).Lockid

To remove the lock using the variable, run the command below:

Remove-AzResourceLock -Lockid $lockid

Summary

Today we covered Azure resource lock, which makes it possible to protect resources and resource groups from improper removal or modification.

In the next post, we’ll talk about resource access control using Access Control (IAM), which lets the administrator control access to resources in Azure.

Did you like the post? Like and share it.

If you have any suggestions or comments, let us know.

[ ]’s

Ulysses Neves

Related guides: Browse the Microsoft Identity Troubleshooting Index or the Microsoft Azure topic archive.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Conditional Access report-only: why a successful sign-in can show a policy failure October 9, 2026
  • Microsoft Entra SMS and Voice Retirement: An Admin Preparation Checklist September 24, 2026
  • Microsoft Defender for Identity domain investigation: six questions to ask first September 10, 2026
  • Microsoft Entra Kerberos key rotation: what changes—and what administrators should check September 6, 2026
  • Microsoft Authenticator Will Block Jailbroken Devices in 2026 — What You Need to Know March 17, 2026

Archives

  • October 2026
  • September 2026
  • March 2026
  • September 2024
  • April 2024
  • February 2024
  • December 2023
  • September 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019

Tags

#aaddownleveldevice #adfs #adfscertificate #adfscertificates #adfsmfaadapter #azureauth #azureCA #azuredevice #capolicy #cloudsummit2021 #conditionalaccess #conditionalaccesspolicy #deviceregistration #farmbehavior #gopasswordless #mfaserver #msidentity #namedlocation #securingazure #securingazuread #sslprivatekey #troubleshootingadfs #troubleshootingwaptrust #tshootadfs #waptrust #webapplicationproxy #WHFBcerttrust #whfbdeployment #WHfBhybridsetup #WHfBprovisioning #widdatabase adconnect AD FS authenticationstrength az500 azurepim Azure security cloudsecurity microsoft365 Microsoft Azure Microsoft Entra hybrid join Microsoft Entra ID Microsoft Entra MFA PowerShell WHfB
©2026 Ulysses Neves | Design: Newspaperly WordPress Theme
Ulysses Neves
Gerenciar Consentimento de Cookies
Para fornecer as melhores experiências, usamos tecnologias como cookies para armazenar e/ou acessar informações do dispositivo. O consentimento para essas tecnologias nos permitirá processar dados como comportamento de navegação ou IDs exclusivos neste site. Não consentir ou retirar o consentimento pode afetar negativamente certos recursos e funções.
Funcional Always active
O armazenamento ou acesso técnico é estritamente necessário para a finalidade legítima de permitir a utilização de um serviço específico explicitamente solicitado pelo assinante ou utilizador, ou com a finalidade exclusiva de efetuar a transmissão de uma comunicação através de uma rede de comunicações eletrónicas.
Preferências
O armazenamento ou acesso técnico é necessário para o propósito legítimo de armazenar preferências que não são solicitadas pelo assinante ou usuário.
Estatísticas
O armazenamento ou acesso técnico que é usado exclusivamente para fins estatísticos. O armazenamento técnico ou acesso que é usado exclusivamente para fins estatísticos anônimos. Sem uma intimação, conformidade voluntária por parte de seu provedor de serviços de Internet ou registros adicionais de terceiros, as informações armazenadas ou recuperadas apenas para esse fim geralmente não podem ser usadas para identificá-lo.
Marketing
O armazenamento ou acesso técnico é necessário para criar perfis de usuário para enviar publicidade ou para rastrear o usuário em um site ou em vários sites para fins de marketing semelhantes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
Ver preferências
  • {title}
  • {title}
  • {title}