-1

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

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

1 Answers1

0

One way you can go about doing this is as follows:

  1. Get all Resource Groups in your Subscription
$AllRGs = $(Get-AzResourceGroup | Select-Object ResourceGroupName).ResourceGroupName
  1. Get the Resource Groups that have locks
$lockedRGs = $(Get-AzResourceLock | Where-Object {$_.ResourceType -eq "Microsoft.Authorization/locks"} | Select-Object ResourceGroupName).ResourceGroupName
  1. Take a diff of the two
$noLockRGs = $AllRGs | Where-Object {$lockedRGs -notcontains $_}
Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30