Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2.7
- import ldap
- ldapDomain = 'ldap://ads00'
- ldapUser = 'USERNAME'
- ldapPass = 'PASSWORD'
- ldapDN = 'OU=Groups,DC=domain,DC=local'
- groupName = 'TS_TERM04_USERS'
- # Get users from Active Directory Groups and store it to files
- def getADGroups():
- l = ldap.initialize(ldapDomain)
- # Set LDAP protocol version used
- l.protocol_version=ldap.VERSION3
- l.set_option(ldap.OPT_REFERRALS, 0)
- l.simple_bind_s(ldapUser,ldapPass)
- results = l.search_s("cn=%s, %s" % (groupName, ldapDN), ldap.SCOPE_BASE)
- for result in results:
- result_dn = result[0]
- result_attrs = result[1]
- if "member" in result_attrs:
- for member in result_attrs["member"]:
- print member
- getADGroups()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement