Can we assign mutiple roles to multiple resources in Azure?

Viewed 121

I've been trying to use PowerShell code to assign multiple roles on multiple resources in Azure, The reason is that we dont use custome roles for cost, below is how i tried to write the code.

$RGs = Import-CSV -Path "C:\input\RBAC-RGs.csv"
$Roles = Import-CSV -Path "C:\input\RBAC-Roles.csv"

$AZAD = Get-AzADGroup -SearchString "Group-Name" #Get Group name Object ID
ForEach ($Group in $RGs) {
Get-AzResourceGroup -Name "$RGs.ResouceGroups" #Get Resource Group resource ID for scope
New-AzRoleAssignment -ObjectId "$AZAD.id" `
-RoleDefinitionName "Storage Account Contributor" `
-Scope "/subscriptions/{subscripotionid}/resourceGroups/resource-group-name"
1 Answers

This is possible. You just have a PowerShell issue within your script:

New-AzRoleAssignment -ObjectId "$AZAD.id" => You have to either omit the quotes here or wrap the property access like this: "$($AZAD.id)".

Related