HowTo: Add Users to Groups Through udm

How To Add Users To Groups Through udm

In case you have multiple users and you need to add them to one group without changing the existing group memberships you can not use UMC for this as it will overwrite existing group memberships.

Step 1

Put the names of your users into a text file called userlist with their uids as follows:

user1
user2
user3
...

Step 2

Get the distinguished names of your users and create a list of them.
Put the following into a file get_dn.sh and start by bash get_dn.sh

#!/bin/bash
rm -f userlist.dn
for i in $(cat userlist) ; do 
 univention-ldapsearch -LLL "uid=$i" dn| grep -vE "^$"| cut -d " " -f2>> userlist.dn
done

Step 3

Identify the distinguished name (dn) of the group you want to add the users ie by the following way:
univention-ldapsearch "cn=Group1" dn

Step 4

Combine the above results to add the users to your groups by using the udm command:

for dn in $(cat userlist.dn) ; do \
udm users/user modify --dn "$dn" --append groups="<DN of GROUP from above>" ; \
done
Mastodon