Good day to all.I have a task to get information from Active Directory (in particular, about access of users to certain groups of rights) and Firebird database. I would like to implement something like this in Python. But I have no idea how to implement it. I searched a lot of materials, but find it hard to systematize. I would be glad to get some help in this matter.
I found a solution to get information from Active Directory here I put modules for Python active_directory, win32api. But after running the scripts I get an error
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-18: ordinal not in range(128)
Something with the coding, but how to solve the problem I do not know. Help!
There are also examples using the ldap module, as advised by the esteemed ctrlok
Here is a working example getting from Active Directory the number of current users and their list
# -*- coding: cp1251 -*-
import codecs, sys
ctrl = 'domain_name'
outf = codecs.getwriter('cp1251')(sys.stdout, errors='replace')
sys.stdout = outf
conn = win32com.client.Dispatch("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open("Active Directory Provider")
query = "SELECT ADsPath FROM 'LDAP://DC="+ctrl+"' WHERE objectClass='user' AND objectCategory='person'"
rs = conn.Execute(query)
users = 
while not rs.EOF:
obj = win32com.client.GetObject(rs.Fields(0).Value)
enabled_users = 
for x in range(len(users)):
def print_user (users):
print u"Number of users %d \n" %(len(users))
for x in range(0, len(users))
print users[x].Name.replace(u'CN=', '')
users = get_all_users_in_domain()
enabled_users = get_enabled_user_in_domain(users)
Now the question is how to add groups to which each user belongs…