In this Azure PowerShell article, we will discuss the syntax, usage of New-AzResourceLock Azure PowerShell cmdlet with examples.
Table of Contents
New-AzResourceLock
New-AzResourceLock is a very good PowerShell command to create a lock for your Azure resource.
Syntax
Below is the syntax of the New-AzResourceLock Azure PowerShell cmdlet.
New-AzResourceLock
-LockName <String>
-LockLevel <LockLevel>
[-LockNotes <String>]
-ResourceName <String>
-ResourceType <String>
-ResourceGroupName <String>
Well, let’s discuss a few examples on the usage of the New-AzResourceLock PowerShell command.
Example
Below is the code that will create a lock for TsInfoWeb website.
New-AzResourceLock -LockLevel CanNotDelete -LockNotes "tsinfo lock detail notes" -LockName "TsInfoWebSiteLock" -ResourceGroupName "MyNewResGrp" -ResourceName "TsInfoweb" -ResourceType "microsoft.web/sites"
After executing the above code, I got the confirmation Pop up. Clicked on the Yes button to confirm.

Then, I got the below output, the resource lock for the website has been created successfully.
PS C:\Users\Bijay> New-AzResourceLock -LockLevel CanNotDelete -LockNotes "tsinfo lock detail notes" -LockName "TsInfoWebSiteLock" -ResourceGroupName "MyNewResGrp" -ResourceName "TsInfoweb" -ResourceType "microsoft.web/sites"
Name : TsInfoWebSiteLock
ResourceId : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5hjk1/resourceGr
oups/MyNewResGrp/providers/microsoft.web/sites/TsInfoweb/provi
ders/Microsoft.Authorization/locks/TsInfoWebSiteLock
ResourceName : TsInfoweb
ResourceType : microsoft.web/sites
ExtensionResourceName : TsInfoWebSiteLock
ExtensionResourceType : Microsoft.Authorization/locks
ResourceGroupName : MyNewResGrp
SubscriptionId : 1cdf4300-dee5-4518-8c8c-feaa72a5hjk1
Properties : @{level=CanNotDelete; notes=tsinfo lock detail notes}
LockId : /subscriptions/1cdf4300-dee5-4518-8c8c-feaa72a5hjk1/resourceGr
oups/MyNewResGrp/providers/microsoft.web/sites/TsInfoweb/provi
ders/Microsoft.Authorization/locks/TsInfoWebSiteLock
You can see the below output here

You can update or modify any parameter of your Resource lock using the Set-AzResourceLock PowerShell command.
If you don’t want the Resource lock anymore, you can use the Remove-AzResourceLock PowerShell command to delete the resource lock in a span of second.
You may also like following the below articles
Wrapping Up
Well, in this Azure article, we have discussed the syntax and usage of the New-AzResourceLock Azure PowerShell cmdlet with examples. Thanks for reading this article !!