[python-win32] enumerating children of an active directory container

Wilbert, Matt (ENV) Wilbert, Matt (ENV)" <Matt.Wilbert@state.ma.us
Mon, 9 Dec 2002 12:42:23 EST


Jens,

Thanks for the timely assistance.  It was the obj. _NewEnum() method
that I was missing.

Matt Wilbert
---------- Original Text ----------

From: <python-win32-request@python.org>, on 12/09/2002 12:00 PM:

Send Python-win32 mailing list submissions to
	python-win32@python.org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.python.org/mailman/listinfo/python-win32
or, via email, send a message with subject or body 'help' to
	python-win32-request@python.org

You can reach the person managing the list at
	python-win32-admin@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-win32 digest..."


Today's Topics:

   1. enumerating children of an active directory container (matt wilbert)
   2. Re: enumerating children of an active directory container (Jens B. 
Jorgensen)

--__--__--

Message: 1
Date: Sun, 8 Dec 2002 19:09:29 EST
To: <python-win32@python.org>
From: "matt wilbert" <Matt.Wilbert@state.ma.us>
Reply-To: "Wilbert, Matt (ENV)" <Matt.Wilbert@state.ma.us>
Subject: [python-win32] enumerating children of an active directory container

Hi,

I am trying to do some work with Active Directory from python 
(ActivePython 2.2.1), but I am having a couple of problems.

Connecting to the domain root using an LDAP:// name works fine,
I can see various properties of the object thus named, , but I
cannot figure out a way to enumerate its children--it appears to
be unimplemented.  Is that correct?  Should I just use ADO?

Also, I can't figure out how I would apply a filter, assuming
that I could do an enumeration.

Thanks,

Matt Wilbert
matt.wilbert@state.ma.us




--__--__--

Message: 2
Date: Mon, 09 Dec 2002 10:26:13 -0600
From: "Jens B. Jorgensen" <jens.jorgensen@tallan.com>
To: "Wilbert, Matt (ENV)" <Matt.Wilbert@state.ma.us>
CC:  python-win32@python.org
Subject: Re: [python-win32] enumerating children of an active directory 
container

This is a multi-part message in MIME format.
--------------040008070605010407060102
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Attached is a very short script that demonstrates child enumeration. You 
give it a path and it prints out everything in that node and all child 
nodes.

matt wilbert wrote:

>Hi,
>
>I am trying to do some work with Active Directory from python 
>(ActivePython 2.2.1), but I am having a couple of problems.
>
>Connecting to the domain root using an LDAP:// name works fine,
>I can see various properties of the object thus named, , but I
>cannot figure out a way to enumerate its children--it appears to
>be unimplemented.  Is that correct?  Should I just use ADO?
>
>Also, I can't figure out how I would apply a filter, assuming
>that I could do an enumeration.
>
>Thanks,
>
>Matt Wilbert
>matt.wilbert@state.ma.us
>
>
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32@python.org
>http://mail.python.org/mailman/listinfo/python-win32
>  
>

-- 
Jens B. Jorgensen
jens.jorgensen@tallan.com

"With a focused commitment to our clients and our people, we deliver value 
through customized technology solutions"  


--------------040008070605010407060102
Content-Type: text/plain;
 name="walkads.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="walkads.py"

from win32com.client import GetObject
import sys

if len(sys.argv) < 2 :
    print 'usage: %s <ADSI path>' % sys.argv[0]
    print 'example: %s WinNT://localhost' % sys.argv[0]
    sys.exit(1)

o = GetObject(sys.argv[1])

def walk(obj, ind) :
    print '%s%s %s' % (' ' * ind, obj.ADsPath, obj.Class)
    en = obj._NewEnum()
    # ok, we'll print out the Properties
    sch = GetObject(obj.Schema)
    for i in sch.MandatoryProperties :
        try :
            print '%s%s = %s' % (' ' * (ind+2), i, obj.Get(i))
        except Exception, e :
            pass
    for i in sch.OptionalProperties :
        try :
            print '%s%s = %s' % (' ' * (ind+2), i, obj.Get(i))
        except Exception, e :
            pass
    if en :
        while 1 :
            i = en.Next()
            if len(i) > 0 :
                walk(i[0], ind+2)
            else :
                break


walk(o, 0)

--------------040008070605010407060102--




--__--__--

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


End of Python-win32 Digest