Hello @Prajith K
Welcome to the Microsoft Q&A and thank you for posting your questions here.
You're asking on how to give Contributor access in 'managedidentity1' to multiple resource group (eg : RG1, RG2, RG3) of Microsoft Azure.
If the above is correct, here I will show you two ways you can do this:
A. PowerShell:
- Open Azure PowerShell and make sure you are connected to your Azure account.
- Run the following commands to assign the Contributor role to the managed identity (managedidentity1) for each resource group (RG1, RG2, RG3):
$resourceGroups = "RG1", "RG2", "RG3"
$managedIdentity = "managedidentity1"
$roleDefinition = Get-AzRoleDefinition -Name "Contributor"
foreach ($resourceGroup in $resourceGroups) {
$scope = "/subscriptions/<subscription-id>/resourceGroups/$resourceGroup"
New-AzRoleAssignment -Scope $scope -ObjectId (Get-AzManagedIdentity -ResourceGroupName $resourceGroup -Name $managedIdentity).PrincipalId -RoleDefinitionId $roleDefinition.Id
}
NOTE: The <subscription-id> should be your own.
B. Azure Portal:
- Navigate to the Azure Portal (https://portal.azure.com/).
- In each resource group, click on "Access control (IAM)" in the left-hand navigation.
- Click on "Add" to add a new role assignment.
- In the "Add role assignment" pane, select the role as "Contributor".
- In the "Assign access to" section, select "Managed Identity" and then choose your managedidentity1.
- Click "Save" to assign the Contributor role to the managed identity for that specific resource group.
- Repeat these steps for each resource group (RG1, RG2, RG3) where you want to grant Contributor access. NOTE: You might need to search for Contributor.
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please remember to "Accept Answer" if answer helped, so that others in the community facing similar issues can easily find the solution. Best Regards, Sina Salam