I’m trying to get some attributes by ldap query as follows:
import win32com.client
ldap="SELECT cn, displayName From 'LDAP://DC=abc,DC=com' WHERE legacyExchangeDN = '{}'"
c = win32com.client.Dispatch('ADODB.Connection')
c.Open('Provider=ADsDSOObject')
rs,rc = c.Execute(ldap.format(dn))
while not rs.EOF:
for e in rs.fields:
print('{}: {}'.format(e.Name, e.Value))
print()
rs.MoveNext()
But it doesn’t work if dn are the following two values.
/o=sinotrans/ou=First Administrative Group/cn=Configuration/cn=Servers/cn=myserver/cn=Microsoft Public MDB
/o=sinotrans/ou=first administrative group/cn=configuration/cn=servers/cn=myserver/cn=microsoft system attendant
I think the exchange object is different from active directory user. But how to change the ldap query expression? Any suggestion is appreciated.
I find out that exchange object is stored at
CN=Configuration,DC=intranet,DC=sinotransand it’s necessary to bind DC server with administrator credential. The following code works with suitiable user name, password and LDAP path.