Advertisement
Javi

Azure: Create subscription owner users

May 29th, 2019
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 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)
  7.  
  8. # Create user group
  9. az ad group create --display-name $GROUP_NAME --mail-nickname $GROUP_NAME
  10.  
  11. # Get user group id
  12. GROUP_ID=$(az ad group list --query "[?displayName=='$GROUP_NAME'].objectId" --output tsv)
  13.  
  14. # Provide ownership of the subscription to the user group
  15. az role assignment create --role "Owner" --assignee-object-id $GROUP_ID --scope /subscriptions/$SUBSCRIPTION
  16. # az role definition list --output json | jq '.[] | {"roleName":.roleName, "description":.description}'
  17.  
  18. # Create 15 users
  19. for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  20. do
  21. az ad user create --display-name $GROUP_NAME$i --password $PASS --user-principal-name $GROUP_NAME$i@$DOMAIN
  22. done
  23.  
  24. # Get the all users Id as a list separated by spaces
  25. USERS_ID=$(az ad user list --query "[?contains(userPrincipalName,'$GROUP_NAME')].objectId" --output tsv)
  26. # Set space as separator for loops
  27. IFS=' '
  28. # Add new users to users group
  29. echo $USERS_ID | while read user; do az ad group member add --group $GROUP_ID --member-id $user; done
  30.  
  31. # Register any desired provider
  32. az provider register --namespace "Microsoft.Devices"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement