I need a powershell script to get a list of all unlocked resource groups. If you run Get-AzureRmResourceLock it will show the resources that are currently locked not the ones that are unlocked
Asked
Active
Viewed 273 times
-1
-
Do you want to check if specific resources have locks or resource groups? – RoadRunner Nov 04 '20 at 08:38
-
@anabell Have you had a chance to check the answer below? Does that help? – Bhargavi Annadevara Nov 06 '20 at 09:29
-
I want to check if resource groups have locks – anabell Nov 09 '20 at 06:21
-
@anabell Please check the provided answer below. Elaborate your requirement if that isn't what you're looking for. – Bhargavi Annadevara Nov 17 '20 at 15:33
1 Answers
0
One way you can go about doing this is as follows:
- Get all Resource Groups in your Subscription
$AllRGs = $(Get-AzResourceGroup | Select-Object ResourceGroupName).ResourceGroupName
- Get the Resource Groups that have locks
$lockedRGs = $(Get-AzResourceLock | Where-Object {$_.ResourceType -eq "Microsoft.Authorization/locks"} | Select-Object ResourceGroupName).ResourceGroupName
- Take a diff of the two
$noLockRGs = $AllRGs | Where-Object {$lockedRGs -notcontains $_}

Bhargavi Annadevara
- 4,923
- 2
- 13
- 30