[python-win32] Translating vbs GetObject("LDAP://...") to Pyt hon?

Tim Golden tim.golden at viacom-outdoor.co.uk
Mon Nov 8 15:26:57 CET 2004


[R. Alan Monroe]
| What is the Python equivalent of this vbs two liner?
| 
| set obj = GetObject("LDAP://cn=johndoe, ou=General Users, 
| ou=Accounts, dc=na, dc=nisource, dc=net")
| wscript.echo obj.Get("description")

Two answers (assuming you do in fact have a johndoe at
the position indicated within the AD)

1) Try this (details changed to suit my local setup):

import win32com.client
obj = win32com.client.GetObject
("LDAP://CN=goldent,CN=Users,DC=gb,DC=vo,DC=local")
print obj.Get ("description")


2) Try this:

Get http://tgolden.sc.sabren.com/downloads/active_directory.py

import active_directory
johndoe = active_directory.find_user ("johndoe")
print johndoe.description

or

import active_directory
users = active_directory.AD_object
(LDAP://ou=Accounts,dc=na,dc=nisource,dc=net)
for user in users.search ("cn='johndoe'"):
  print user.description


I keep meaning to put up a page to explain how the module works,
but basically it just does a bit of the not-too-heavy lifting
when it comes to common operations on Active Directory.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. 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