Reputation: 33
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
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