I am trying to add member to Active Directory group with script using python-ldap module. Here are my attempt so far:
import ldap
from ldap import modlist as modlist
l = ldap.initialize(server)
l.simple_bind_s(username, password)
l.set_option(ldap.OPT_REFERRAL)
old_members = new_members = dict()
new_members['member'] = 'cn=Forename Name,ou=Users,dc=DOMAIN'
old_members
group_dn = 'cn=GROUP,ou=Groups,dc=DOMAIN'
try:
ldif = modlist.modifyModlist(old_members,new_members)
l.modify_s(group_dn, ldif)
except ldap.LDAPError,e:
print e
I got this error: LdapError: DSID-0C090C48, comment: Error in attribute conversion
I have no idea where does this error comes from, after having searched Google up and down.
I would be really happy having a hint, or an other way to add user to group, which should be quite a common task from python-ldap
Many thanks
Best Answer
I was looking at your code, and I think this line creates two pointers to the same dictionary:
old_members = new_members = dict()
This would cause the ldif object to be equal to [] when you run this line:
ldif = modlist.modifyModlist(old_members,new_members)