You can do quite a lot with win32com.client as well (I had problems finding documentation). For example, I needed to allow a userβs email, knowing his ADS_NAME_TYPE_NT4 formatted name ( doman\jonjoe ).
First of all, you need to convert it to the format ADS_NAME_TYPE_1779 ( CN=Jeff Smith,CN=users,DC=Fabrikam,DC=com ):
name_resolver = win32com.client.Dispatch(dispatch='NameTranslate') name_resolver.Set(3, 'domain\\jonjoe') ldap_query = 'LDAP://{}'.format(name_resolver.Get(1))
After that, you can simply call GetObject() :
ldap = win32com.client.GetObject(ldap_query) print(ldap.Get('mail'))
Tested with Python 3.2.5
source share