[python-win32] ADSI and LDAP Searches

Mark Hammond mhammond at skippinet.com.au
Thu Dec 8 22:00:37 CET 2005


Consider looking at the win32comext\adsi\demos directory - search.py has an
example.  This module exposes the ADSI interfaces "natively", rather than
using IDispatch object.

Mark

> -----Original Message-----
> From: python-win32-bounces at python.org
> [mailto:python-win32-bounces at python.org]On Behalf Of Gooch, John
> Sent: Friday, 9 December 2005 4:22 AM
> To: python-win32 at python.org
> Subject: [python-win32] ADSI and LDAP Searches
>
>
> I am trying to get my Python script to search Active Directory for users
> with a certain login name and then have it return their adspath
> attribute. Previously, I had a working script that used Tim Golden's
> active_directory module, but since the more recent round of NT Server
> patches, it no longer works, so now I am trying to make a work around to
> this issue.
>
> Here is what I have that is working ( in my test script ):
>
> ________________________________
> import win32com.client
> username = "John.Gooch"
>
>
> adsi = win32com.client.Dispatch('ADsNameSpaces')
> ldap = adsi.getobject('','LDAP:')
> DSO = ldap.OpenDSObject( "LDAP://MER2-ECHDC2.echostar.com","","", 1)
> _________________________________
>
> It works up to here, so now I assume I am connected to Active Direcory
> and can now run an LDAP-style search:
> _________________________________
> DSO.execute("<LDAP://ou=echostar,ou=com>;(cn=*);adspath;top")
> _________________________________
>
> Ok,no go on that line( throws error "AttributeError: <unknown>.execute"
> , but then I am complete guessing the syntax based upon an old Perl
> script I had that used to do this job.
>
>
> Does anyone have a working example of searching Active Directory? Of you
> course you can put in made up domain/server names where necessary.
>
> Thank You,
>
>
> John A. Gooch
> Systems Administrator
> IT - Tools
> EchoStar Satellite L.L.C.
> 9601 S. Meridian Blvd.
> Englewood, CO  80112
> Desk: 720-514-5708
>
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32



More information about the Python-win32 mailing list