Hamadah
Hamadah

Reputation: 33

Can we assign mutiple roles to multiple resources in Azure?

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"

Upvotes: 3

Views: 323

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

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)".

Upvotes: 1

Related Questions