Here is a simple python/adsi example

John Nielsen nielsenjf at my-deja.com
Wed Sep 15 22:33:02 EDT 1999


A few people had asked about adsi and python.

Well, I've started to play with it and here are some simple examples
to get one started. You will need to download adsi from microsoft:

http://www.microsoft.com/windows/server/Technical/directory/adsilinks.as
p

Microsoft has documentation for using languages other than python is the
sdk.

Here are some simple examples, talking to an exchange server
-------

# Create the Global Providers object
adsiNameSpaces = win32com.client.Dispatch('ADsNameSpaces')

# Now get the LDAP Provider object
ldapNameSpace = adsiNameSpaces.getobject("","LDAP:")

#setup the login info to the exchange server
ex_path="LDAP://server/cn=fredflint,cn=Recipients,ou=rubble,o=bedrock"
logon_ex='cn=wilma, dc=bedrock'
password='dino'

myDSObject = ldapNameSpace.OpenDSObjec(ex_path,logon_ex,password,0)
myDSObject.Getinfo()

#To get data try:
attribute = myDSObject.Get('Extension-Attribute-1')
print attribute

#To set data try:
myDSObject.Put('Extension-Attribute-1','barney was here')
myDSObject.Setinfo()


#Use a similar approach to add new accounts, except you start with:
ex_path="LDAP://server/cn=Recipients,ou=rubble,o=bedrock"
logon_ex='cn=wilma, dc=bedrock'
password='dino'

myDSObject = ldapNameSpace.OpenDSObjec(ex_path,logon_ex,password,0)

#now create the new entry
newobj = myDSObject.create("OrganizationalPerson", "cn=betty")
newobj.put('MailPreferenceOption', 0)
#etc . . . add whatever else you want. There are a few required fields.
newobj.SetInfo

----------
There are problems with associating the new exchange account with a NT
account. It require sids and security descriptors that I haven't
figured out yet.

Hope this helps some of you out,

john



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list