The REST API, CLI, and ARM templates all apply changes to a single resource at a time. The answer to your issue is to use a loop, which the CLI, ARM, and SDKs are all capable of doing. Is there a way to identify which labs need to be changed through a script? If they are all the labs in the subscription, all in a given resource group or all labeled a certain way this could be automated through one of those methods. If you would be willing to share a bit more about the setup then I'd be happy to help with putting together the script.
EDIT: Example script for Powershell/CLI
IMPORTANT NOTE The rest call to update the lab is correct according to the docs, but not working as intended. I've reached out to the product team to see how to resolve it
#login if not already
try {
az account show
} catch {
az login
}
#this script is for a single sub, but could also nest loops from an array of subscription IDs or by 'az account list' to get all subscriptions accessible to the user
$subId = "<subId>"
$createIdentity = $true
$identityGroup = "<resourceGroup"
$identityName = "realm-vm-identity-XXXXXXXX"
$id = [PSCustomObject]@{}
if($createIdentity) {
$id = az identity create -g $identityGroup -n $identityName | ConvertFrom-Json
}
else {
$id = az identity get -g $identityGroup -n $identityName | ConvertFrom-Json
}
#get the list of labs for this subscription
$labs = az rest --method GET --url "/subscriptions/$subId/providers/Microsoft.DevTestLab/labs?api-version=2018-09-15&`$filter=startswith(name, 'bb')" | ConvertFrom-Json
#update each lab in the subscription
$labs.value | ForEach-Object {
$body = "{'location': '$($_.location)','identity':{ 'type': 'userAssigned','userAssignedIdentities':{'$($Id.id)':{}}},'properties':{'identityUsageType':'Environment'}}"
$updateUri = "https://management.azure.com/subscriptions/$subId/resourceGroups/$($_.resourceGroup)/providers/Microsoft.Devtestlab/labs/$($_.name)/serviceRunners/$($id.name)?api-version=2018-09-15"
az rest --method PUT --uri $updateUri --body $body
}