With help I have been able to put together a little example. It illustrates several different ways..
import win32com.client c = win32com.client.Dispatch("ADODB.Connection") c.Open("Provider=ADSDSOObject") ##Check if connected to AD if bool(c.state): print "Connected to AD" ## This uses sql dialect with no command object ##rs,rc=c.Execute(""" ##SELECT adspath, title, name ##From 'LDAP://DC=AD,DC=LOCAL' ##where objectCategory='Person' and objectClass='user' and name='*' ##""") ##This uses ADSI dialect with not command object ##rs,rc=c.Execute(""" ##<LDAP://DC=AD,DC=LOCAL>;\ ##(&(objectCategory=Person)(objectClass=user)(name=*));\ ##name,adspath,title;\ ##subtree ##""") ##Command com with properties in sql dialect ##comm = win32com.client.Dispatch("ADODB.Command") ##comm.ActiveConnection = c ##comm.Properties('Page size').value=1000 ##comm.CommandText = ("""\ ##SELECT adspath, title, name \ ##From 'LDAP://DC=AD,DC=LOCAL' \ ##where objectCategory='Person' and objectClass='user' and name='*'\ ##""") ##rs,rc=comm.Execute() ##Command com with properties in ADSI dialect ##ADS_SCOPE_SUBTREE = 2 ##ADS_SCOPE_ONELEVEL = 1 ##ADS_SCOPE_BASE = 0 ##comm = win32com.client.Dispatch("ADODB.Command") ##comm.ActiveConnection = c ##comm.Properties('Page size').value=1000 ##comm.Properties('searchscope').value=ADS_SCOPE_SUBTREE ##comm.CommandText = ("""<LDAP://DC=AD,DC=LOCAL>;\ ##(&(objectCategory=Person)(objectClass=user)(name=*));\ ##name,adspath,title;""") ##rs,rc=comm.Execute() ##Connect using recordset object in ADSI Dialect ##rs = win32com.client.Dispatch("ADODB.recordset") ##rs.ActiveConnection = c ##rs.source = ("""<LDAP://DC=AD,DC=LOCAL>;\ ##(&(objectCategory=Person)(objectClass=user)(name=*));\ ##name,adspath,title;\ ##subtree""") ##rs.Open() ##Connect using recordset object in sql Dialect ##rs = win32com.client.Dispatch("ADODB.recordset") ##rs.ActiveConnection = c ##rs.source = ("""\ ##SELECT adspath, title, name \ ##From 'LDAP://DC=AD,DC=LOCAL' \ ##where objectCategory='Person' and objectClass='user' and name='*'\ ##""") ##rs.Open() ##while not rs.EOF: ## for f in rs.Fields: ## print f.Name, f.Value ## rs.MoveNext() c.close c = None -- http://mail.python.org/mailman/listinfo/python-list