1

Creating 20+ Azure Resource Group with Locks two locations in the US (West and East). I can not fine JSON template or cli template which would let me create them through user prompt in the terminal or through JSON parameter in the console. I cant be creating one by one for both the regions using

New-AzureRmResourceGroup -Name $rgName -Location $locName

Closest i saw in MS site is the below -

variables

`$labPrefix = "Mlab"
$labnumber = "2017"
$labsubnet = "55"
$rgName = $labPrefix + $labnumber #New resource group name
$locName = "West Europe" # Loation of new resource group
$saName = $rgName.Replace("-","").tolower() 
$saType="Standard_LRS" # Storage account type`

If i was creating RG as Mlab2017 - this would work. but mine would have 4 different labPrefix and 4 different labnumber. I cant seem to find a better solutions for this. any help on creating the json array with or shell script array to pass and create the RG with Locks will be highly appreciated.

Vivek Kumar Singh
  • 3,223
  • 1
  • 14
  • 27
AmigoSe
  • 366
  • 1
  • 2
  • 13

1 Answers1

1

You could use template to create resource groups firstly, then you could use Power Shell to lock resource groups in specific area. For example:

$location1 = "eastus"
$location2 = "westus"
$rg=Get-AzureRmResourceGroup |Where-Object{($_.Location -eq $location1) -or ($_.Location -eq $location2)}
$rgnames = $rg.ResourceGroupName
foreach ($rgname in $rgnames)
{
    $lockname = $rgname+"lock"
    New-AzureRmResourceLock -LockName $lockname -LockLevel CanNotDelete -ResourceGroupName $rgname
}

You also could check this link.

Shui shengbao
  • 18,746
  • 3
  • 27
  • 45