2017-06-17 105 views
1

我試圖使用Python-LDAP3將用戶添加到組LDAP3蟒用戶添加到

conn.modify(CN =跳舞,OU =測試組,DC =立場,DC = LSD「 { 'memberuid':[(MODIFY_REPLACE,[CN =用戶1,OU =用戶,DC =立場,DC = LSD'])})

但在ActiveDirectory中沒有改動

什麼錯誤?

+0

完成 ldap3.extend.microsoft.addMembersToGroups.ad_add_members_to_groups(康涅狄格州,[ 'CN = sonny.lamb,OU =安哥拉,OU =測試鷗,DC =支架,DC = LSD'],[」 CN =跳舞,OU =測試的基團,DC =支架,DC = LSD']) –

回答

1
from ldap3 import Server, Connection, ALL, NTLM 
from elizabeth import Personal, Address,Text 
from ldap3.extend.microsoft.addMembersToGroups import ad_add_members_to_groups as addUsersInGroups 
import random 

serverName='dc1.stand.local' 
connUser="stand.lsd\\Admin" 
connUserPwd="" 
usersOU = 'ou=test-ou,dc=stand,dc=local' 
groupsOU = 'ou=test-groups,dc=stand,dc=local' 

usersDnList = [] 
groupsDnList = [] 

server = Server(serverName, get_info=ALL) 
conn = Connection(server, user=connUser, password=connUserPwd, authentication=NTLM) 
conn.bind() #must be TRUE 

conn.add(usersOU, 'organizationalUnit') # add test-ou for users 
conn.add(groupsOU, 'organizationalUnit') # add test-ou for groups 

data = Text('en') 
for _ in range(0,10): 
    currentGroup = 'cn='+data.word()+',ou=test-groups,dc=stand,dc=local' 
    groupsDnList.append(currentGroup) 
    conn.add(currentGroup, 'group') 

address = Address('en') 
person = Personal('en') 
for _ in range(0,10): 
    address_country = address.country() 
    conn.add('ou='+address_country+',ou=test-ou,dc=stand,dc=local', 'organizationalUnit') 
    for _ in range (0,10): 
     name = person.name(gender='male') 
     surname = person.surname(gender='male') 
     currentUser = 'cn='+name+'.'+surname+','+'ou='+address_country+',ou=test-ou,dc=stand,dc=local' 
     usersDnList.append(currentUser) 
     conn.add(currentUser, 'User', 
     {'givenName': name, 
     'sn': surname, 
     'departmentNumber': 'DEV', 
     'telephoneNumber': 1111}) 

for _ in range(0,300): 
    rndUser = random.choice(usersDnList) 
    rndGroup = random.choice(groupsDnList) 
    addUsersInGroups(conn, rndUser, rndGroup)