[python-win32] AD get user info script
nugentm at myrealbox.com
nugentm at myrealbox.com
Wed Jan 14 14:17:56 EST 2004
I wrote this script as a quick way to get AD properties of a LDAP object. Just make sure makepy is run on the ADO recordset library and rename to ADO.py LDAP://floex0ex01.ffci.com is our PDC emulator; it has all of the user objects on it. Just run the script and give a string to search.
import ADO, time
from string import atoi
from win32com.client import GetObject
def adoSearch(searchString):
adoConnection=ADO.Connection()
adoCommand=ADO.Command()
adoRecordset=ADO.Recordset()
adoConnection.Provider="ADsDSOObject"
adoConnection.Open()
command="Select ADsPATH from 'LDAP://floex0ex01.ffci.com' where cn='*%s*'" % searchString
adoCommand.ActiveConnection=adoConnection
adoCommand.CommandText=command
adoRecordset.Open(adoCommand)
adoRecordset.MoveLast()
count=adoRecordset.RecordCount
adoRecordset.MoveFirst()
RecordsetList=[]
for item in range(count):
adspath=adoRecordset.Fields(0).Value
RecordsetList.append(adspath)
adoRecordset.MoveNext()
return count,RecordsetList
def adoGet(Path):
obj=GetObject(Path)
en=obj._NewEnum
sch=GetObject(obj.Schema)
for i in sch.MandatoryProperties:
try:
print i + " " + str(obj.Get(i))
except:
pass
for i in sch.OptionalProperties:
try:
if i in ['whenCreated','whenChanged']:
print i + " " + str(obj.Get(i).Format())
else:
print i + " " + str(obj.Get(i))
except:
pass
Searchstr=raw_input('Type in a String.')
(rscount,rsList)= adoSearch(Searchstr)
print rscount
index=0
print " Index Path"
for i in rsList:
print " %s %s" % (index,i)
index=index+1
print """ Please Select an Entry to Get
"""
Entry=atoi(raw_input('Entry?'))
adoGet(rsList[Entry])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20040114/95952981/attachment.html
More information about the Python-win32
mailing list