group_name="YourGroupName" # Replace with the name of the Azure AD group
# Define an array of UPNs of users to add to the group
user_upns=("user1@example.com" "user2@example.com" "user3@example.com")
# Loop through the array and add each user to the Azure AD group
for upn in "${user_upns[@]}"; do
# Get the object ID of the user
user_object_id=$(az ad user show --upn "$upn" --query objectId --output tsv)
# Add the user to the Azure AD group
az ad group member add --group "$group_name" --members "$user_object_id"
done
You can use the above script to add multiple users to a group, You can use the same priniciple to tweak it for your requirements
Please click "Accept as answer" if it helps.