Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- GROUP_NAME=<name of the group>
- PASS=<default password>
- DOMAIN=<domain>.onmicrosoft.com
- SUBSCRIPTION=$(az account list --query "[?isDefault]".id --output tsv) && echo Subscription: $SUBSCRIPTION
- az group create --name common-rg --location westeurope > /dev/null && echo Common group created.
- # Create user group
- 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.
- # Create 50 users
- for i in {1..50}
- do
- 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
- az ad group member add --group $GROUP_ID --member-id $USER_ID
- RESOURCE_GROUP=$GROUP_NAME${i}-rg
- az group create --name $RESOURCE_GROUP --location westeurope --output table
- 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.
- 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.
- done
- # Provide ownership of the subscription to the user group
- # GROUP_ID=$(az ad group list --query "[?displayName=='$GROUP_NAME'].objectId" --output tsv) && echo $GROUP_ID
- # az role assignment create --role "Owner" --assignee-object-id $GROUP_ID --scope /subscriptions/$SUBSCRIPTION
- # az role definition list --output json | jq '.[] | {"roleName":.roleName, "description":.description}'
- # Owner of the subscription:
- # az role assignment create --role "Owner" --assignee $GROUP_ID --scope /subscriptions/$SUBSCRIPTION
Add Comment
Please, Sign In to add comment