Locking VMs and Resources Groups with Azure Resource Manager using Azure PowerShell

Hello Folks!

In this blog post we will be talking about locking down your Azure Resources with Azure Resource Manager. This tutorial might come handy to you when you want your resources to be safe from getting accidentally deleted. You can lock almost any type of resource using this method be it Virtual Machines, Web Apps, NICs, Resource Groups, etc. When locked, authorized users can still read and modify the resources, but they can't delete the resources.


I will assume you have the following pre-requirements completed:

  1.  An Azure Subscription
  2. A VM created using Resource Manager in a Resource Group.
  3. Make sure you are either the owner of the Azure Subscription or you are the User Administrator.
  4. You have the Latest Azure PowerShell installed.

So let’s start.

Step 1: Login to your Azure Subscription

Open Azure PowerShell and login with your credentials.




Step 2: Find Your Resource Type

In this step we are trying to find the resource type of our particular resource. For this, run this cmdlet and find the parameter resource type in the output. As the parameter for the ‘–ResourceNameContains’ you can replace with the name of your own resource. In this example, it’s a VM with the name WinServerVM.



Copy down the value for resource type. In this case it is:


Paste down this value in the ‘-ResourceType’ parameter in the next step.

Step 3: Locking Down Your Resource

Run this cmdlet and replace the value of –ResourceType with the value of ResourceType parameter you obtained in the Previous Step.

New-AzureRmResourceLock -LockLevel CanNotDelete –LockName LockRmVM -ResourceGroupName CloudySingh-RG -ResourceName WinServerVM –ResourceType Microsoft.Compute/virtualMachines



Alt Text

Your resource is successfully locked. Let us try to delete this resource (VM here).

Failed to Delete the VM


You will receive this error.


Step 4: Unlocking Your Resource

You can unlock your resource anytime using this cmdlet.

Remove-AzureRmResourceLock -LockName LockRmVM -ResourceGroupName CloudySingh-RG -ResourceName WinServerVM -ResourceType Microsoft.Compute/virtualMachines


Locking Your Resource Groups

You can also lock the whole Resource Group using this cmdlet.

New-AzureRmResourceLock -LockLevel CanNotDelete -LockName LockRG -ResourceGroupName CloudySingh-RG


So, thank you friends. If you have any queries feel free to ask in the comments. You can also follow me on twitter @SinghCloudy.

For all latest blogs and news please follow @ecanarys

Thanks & Regards

Karanmeet Singh



Azure Blob Storage: The PowerShell Way!

Hi folks!Great to see you again.This blog post is purely based on Azure Blob Storage: The PowerShell...

Read More >

Create a Windows Server 2012 R2 VM using ARM in Azure PowerShell

Hi Folks,In this Blog Post we will learn how to create an Azure ARM Virtual Machine using Azure Powe...

Read More >

Continuous Integration/ Continuous Deployment VSTS

Following the below steps you can build and deploy your ASP.NET  app to Azure from either Visua...

Read More >

How to Sync On-premise AD with Windows Azure AD using Azure AD Connect tool

 Azure AD is a service that provides identity and access management capabilities in the cloud. ...

Read More >

Creating a Point-to-Site Connectivity using Azure Resource Manager

Configure a Point-to-Site connectivity to a VNet using PowerShell (ARM Mode)Task 1: Create a Self-Si...

Read More >

How to Create an Azure Virtual Network by using a Deployment Template

Hello Folks!In this Blog post, we will try to learn how to create an Azure V-Net using an ARM templa...

Read More >

Microsoft Azure: Implementing Internet Facing Load Balancers using Azure Resource Manager

Howdy Folks!I was exploring Network Load Balancer in Azure Resource Manager and found out that you c...

Read More >

Microsoft Azure Stack : Power of Azure in our datacentre

Why Azure Stack?Microsoft Azure Stack is a new hybrid cloud platform product that enables our organi...

Read More >

Microsoft Azure : Mobile Services - Xamarian.Android with .Net

NOTE: Microsoft Azure recommends Azure App Service Mobile Apps for all new mobile backend deployment...

Read More >

Microsoft Azure : The cloud for modern business

 Why Azure? Microsoft Azure: Cloud Computing Platform and Services Move faster Save Money ...

Read More >



I always emailed this blog post page to all my friends, since if like to read it afterward my friends will too.Build muscle site how to pump the press
4/7/2021 6:43:48 PM | Reply
Thanks for this incredible piece. I really enjoyed reading this and have to say one thing - that you are an incredible writer.I actually don't usually bookmark origin - that the last time I did this is http://www.ahewar.org/links/dform.asp?url=https://makeup-reviews.com/moisturizers/tata-harper-repairative-moisturizer/. And I do wish to see more of your articles in my bookmarks. Thank you for the work, have a fantastic day.
3/3/2021 8:30:36 AM | Reply
fantastic issues altogether, you just won a brand nnew reader. Whhat could you suggest about your put uup that you just made a few days in the past? Any certain?Farmacología deportiva homepage hombre fuerte
2/11/2021 1:23:23 AM | Reply
Darn, content enjoy this specific makes waking up worth the initiative! Checking out in in the sack nowadays I acquired thus encouraged I really chose to work out. Thanks for practically creating my whole entire lifestyle better. The only device that utilized to be capable to do that was actually https://www.slots43.com/eu-online-casinos/casumo-review/, but now I seem like you got the durability.
7/25/2020 11:10:14 AM | Reply
Hello there, You've done a great job. I'll definitely digg it and personally suggest to my friends.I am confident they will be benefited from this website.http://ural-news.net/other/2020/01/26/217627.html bet football betting match
4/23/2020 12:15:51 PM | Reply
These services often involve interacting with and ensuring customers in their own homes.
2/19/2020 3:32:41 PM | Reply

Post a Comment

Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive

Contact Us
  • *
  • *