[Tutor] Python and Active directory

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Wed Mar 31 11:14:02 EST 2004


Here is something to start with (code courtesy of
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=2f3c
ef424c.tim%40worthy.demon.co.uk&rnum=2&prev=/groups%3Fq%3Dwin32com.clien
t.getobject%2520ldap%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26sa%3D
N%26tab%3Dwg ):

#begin code
import win32com.client #from Mark Hammond's pywin32 module

def do_onecontainer(Container):
    for oneobject in Container:
        if oneobject.Class.lower()=='user': #found a user! do what you
want here (print, write to file, add to database, etc)
            print oneobject.cn 
 
        if oneobject.Class.lower()=="organizationalunit" or \
        oneobject.Class.lower()== "container": #found a subcontainer -
search it for users by recursively calling do_onecontainer()
            do_onecontainer(oneobject)

startContainer=win32com.client.GetObject("LDAP://DC=yourdomain,DC=suffix
") #make sure to set your domain info

do_onecontainer(startContainer)
#end code

There is probably a way to do this with ADODB and LDAP queries, but this
works.

Christian
http://www.dowski.com


-----Original Message-----
From: Wilhelmsen Jan [mailto:Jan.Wilhelmsen at bilia.no] 
Sent: Tuesday, March 30, 2004 5:06 AM
To: tutor at python.org
Subject: [Tutor] Python and Active directory


Hi!
 
Is there any module or other ways of extracting/listing/modifying
users/person account  information from Active directory?
If there is? Where can I find information about this?
 
I need to make a script that exports all users in all OU's to a
formatted textfile.
 
 
Thanks!
 
Jan Wilhelmsen



More information about the Tutor mailing list