I have 300 resource groups in Azure and i want to assign Owner access to 250 resource groups. Individually I have to assign the owner access on each resource group is time consuming task. Is there is any other way to do this?
Hi All,
I have 300 resource groups in Azure subscription and I want to assign 'Owner' role to 250 resource groups only. Individually I have to assign the 'owner' role on each resource group is time consuming task. Is there is any other way to do this?
CodePudding user response:
I tried to reproduce same in my environment I got the results successfully like below.
To assign owner access to all the resource groups you can make use of below PowerShell comment like below:
Connect-AzAccount
$resourceGroups = Get-AzResourceGroup
$resourceGroups | ForEach-Object {
New-AzRoleAssignment -ObjectId <USER OBJECTID> -RoleDefinitionName "Owner" -Scope $_.ResourceId
}
To get object ID of credentials or user Go to azure active directory -> user -> select user -> object ID like below:
According to your scenario as you have 300 resource groups and you want to assign owner access to 250 resource groups try the below.
Go to resource group and export csv file and remove resource group which you don't want to assign access keep only resource group which you want to assign owner role in csv file like below:
When I use the PowerShell command I am able to assign owner access to list of multiple resource groups like below:
# Import CSV file with resource group names
$resourceGroups = Import-Csv -Path <PATH OF YOUR CSV FILE>
foreach ($resourceGroup in $resourceGroups) {
# Assign the role to the user or group
New-AzRoleAssignment -ObjectId ad4818XXXXXXXX -RoleDefinitionName "Owner" -ResourceGroupName $resourceGroup.ResourceGroupName
}
Output:
CodePudding user response:
You can't create a script to do this? I'm not real savvy on the Azure stuff but I had a shell script (bash) that would do something similar to this for hundreds of users and groups assignments. It was a long time ago, I'll try to find it if you want.