[python-win32] User Info from AD

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Jan 14 03:24:12 EST 2004


> 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")

which equates to this in python (assumes you have installed win32all
extensions):

<code>
import win32com.client
domain_name = "VOUK"
user_name = "goldent"
user = win32com.client.GetObject ("WinNT://%s/%s,user" % (domain_name,
user_name))
</code>

And then you just iterate over the user.Groups () method, like this:

<code>
group_names = []
for group in user.Groups ():
  group_names.append (group.Name)

print group_names
</code>

The stuff with the dictionary you can ignore, because
 you'll be using Python's own structures: lists of Dicts
 depending on what you want to do.

TJG


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-win32 mailing list