Group Membership in Active Directory Query

Tim Golden mail at timgolden.me.uk
Fri Feb 16 16:28:14 EST 2007


Kooch54 wrote:
>>      Thanks for your response and Uwe I apologize if I misunderstood
>> and misinterpreted your comments.  I am sorry.
>> I have tried Tim's module called active_directory and it works really
>> well.  But I can't figure out how to connect to a specific group is I
>> know the common name for it but not the DN and then return it's
>> members.  

For the simple "group in my domain" situation, as
far as I can see you can do something like this:

<code>
import active_directory
for group in active_directory.search (
   "sAMAccountName='sharedaccess'",
   "objectClass='group'"
):
   print group
   for member in group.members:
     print member

</code>

(I'm not on an AD-connected machine just now, but I
think that'll do it).

As to finding it another domain, I'm not sure. I suspect
that if you simply issue the above query, you'll get
the groups back from all domains in the forest. But I'm
not sure about that. In essence this isn't a Python question
as such. If you can find out from any source how to formulate
the query in an AD way, I'm quite sure we can translate that
easily into Python.

I'm afraid that my AD module is a very lightweight wrapper
over the LDAP:// object system and offers very little support
(and gets very little attention from me). Hopefully I can
have a boost of energy & time and give it some help.

TJG



More information about the Python-list mailing list