forked from tomwechsler/Azure_Administrator_Associate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Azure_Resource_Locks.ps1
36 lines (25 loc) · 1.28 KB
/
Azure_Resource_Locks.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Set-Location C:\
Clear-Host
#We need the module
Install-Module -Name Az -Force -AllowClobber -Verbose
#Log into Azure
Connect-AzAccount
#Select the correct subscription
Get-AzSubscription -SubscriptionName "MSDN Platforms" | Select-AzSubscription
$RGName = "resourcegroupname"
#To lock a resource, provide the name of the resource, its resource type, and its resource group name
New-AzResourceLock -LockLevel CanNotDelete -LockName LockSite -ResourceName examplesite -ResourceType Microsoft.Web/sites -ResourceGroupName $RGName
#To lock a resource group, provide the name of the resource group
New-AzResourceLock -LockName LockGroup -LockLevel CanNotDelete -ResourceGroupName $RGName
#To get information about a lock
Get-AzResourceLock
#To get all locks for a resource
Get-AzResourceLock -ResourceName examplesite -ResourceType Microsoft.Web/sites -ResourceGroupName $RGName
#To get all locks for a resource group
Get-AzResourceLock -ResourceGroupName $RGName
#To delete a lock for a resource
$lockId = (Get-AzResourceLock -ResourceGroupName $RGName -ResourceName examplesite -ResourceType Microsoft.Web/sites).LockId
Remove-AzResourceLock -LockId $lockId
#To delete a lock for a resource group
$lockId = (Get-AzResourceLock -ResourceGroupName $RGName).LockId
Remove-AzResourceLock -LockId $lockId