[python-win32] User Info from AD

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Wed Jan 14 09:49:19 EST 2004


> -----Original Message-----
> > I'm trying to get a list of groups that an Active Directory user 
> > belongs
> to.  It is win 2000.
> > [... snip most of .vbs function ...]
> 
> OK. The important bit is this:
> 
> Set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName &
> ",user")

You can also bind to the user object via LDAP:
import win32com.client
userDN = 'CN=Joe Schmoe, OU=Customer Support, OU=Employees,
DC=yourdomain, DC=com'
user = win32com.client.GetObject('LDAP://' + userDN)

You can then get the groups that the user belongs to in this manner:

for group in user.memberOf:
    print group

I believe that LDAP is the "preferred" way to work with AD.  Whether you
prefer it or not, of course, is a different story ;-)

Christian
http://www.dowski.com



More information about the Python-win32 mailing list