You are here: Home / Documentation / How To's / How to import users into a group

How to import users into a group

by kimadmin — published Nov 10, 2010 12:35 PM, last modified Aug 16, 2016 10:50 AM
a script that takes a list of users and adds them to a group

Via ZMI add a Script (Python), call it .importGroupMembers:

# takes list of email addresses and populates the group with those members

targetGroupTitle = 'Fair Trade Intranet Viewers'
groupMembers = [ '', '', ]

pg = container.portal_groups
group = pg.getGroupById(targetGroupTitle)
if group:
    print "found group %s" % group
    currentMembers = [m.getId() for m in group.getGroupMembers()]
    for m in groupMembers:
        mId = m.replace('', '').replace(' ', '')
        print "checking %s..." % mId
        if mId in currentMembers:
            print "    already a member"
            print "    adding %s to group" % mId
    print "no such group exists"

return printed

Change the values of the targetGroupTitle and of the list of group members.  Here we listed their full email addresses, so in the for loop we strip out the "" portion of their email address to get their LDAP user account ID.