Javi

Azure: Create resource group owner users

Aug 26th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. GROUP_NAME=<name of the group>
  4. PASS=<default password>
  5. DOMAIN=<domain>.onmicrosoft.com
  6. SUBSCRIPTION=$(az account list --query "[?isDefault]".id --output tsv) && echo Subscription: $SUBSCRIPTION
  7.  
  8. az group create --name common-rg --location westeurope > /dev/null && echo Common group created.
  9.  
  10. # Create user group
  11. GROUP_ID=$(az ad group create --display-name $GROUP_NAME --mail-nickname $GROUP_NAME --query objectId --output tsv) && echo AD group $GROUP_NAME created with ID $GROUP_ID.
  12.  
  13. # Create 50 users
  14. for i in {1..50}
  15. do
  16. USER_ID=$(az ad user create --display-name $GROUP_NAME$i --password $PASS --user-principal-name $GROUP_NAME$i@$DOMAIN --query "objectId" --output tsv) && echo UserId for $GROUP_NAME$i: $USER_ID
  17. az ad group member add --group $GROUP_ID --member-id $USER_ID
  18. RESOURCE_GROUP=$GROUP_NAME${i}-rg
  19. az group create --name $RESOURCE_GROUP --location westeurope --output table
  20. az role assignment create --role "Owner" --assignee $GROUP_NAME$i@$DOMAIN --resource-group $RESOURCE_GROUP > /dev/null && echo User $GROUP_NAME$i@$DOMAIN assigned as owner of resource group $RESOURCE_GROUP.
  21. az role assignment create --role "Contributor" --assignee $GROUP_NAME$i@$DOMAIN --resource-group common-rg > /dev/null && echo User $GROUP_NAME$i@$DOMAIN assigned as contributor of resource group common.
  22. done
  23.  
  24. # Provide ownership of the subscription to the user group
  25. # GROUP_ID=$(az ad group list --query "[?displayName=='$GROUP_NAME'].objectId" --output tsv) && echo $GROUP_ID
  26. # az role assignment create --role "Owner" --assignee-object-id $GROUP_ID --scope /subscriptions/$SUBSCRIPTION
  27. # az role definition list --output json | jq '.[] | {"roleName":.roleName, "description":.description}'
  28.  
  29. # Owner of the subscription:
  30. # az role assignment create --role "Owner" --assignee $GROUP_ID --scope /subscriptions/$SUBSCRIPTION
Add Comment
Please, Sign In to add comment