No subject

Tim Golden mail at timgolden.me.uk
Tue Apr 21 18:11:57 CEST 2009


karlos barlos wrote:
> ok sorry TIM 
> 
> I just took some piece of code  that ADDs users to AD 
> 
> <CODE>
>  import win32com,win32com.client
>         def add_acct(location,account):
>           ad_obj=win32com.client.GetObject(location)
> 
>           ad_user=ad_obj.Create('user','cn='+user['login'])
>           ad_user.Put('sAMAccountName',user['login'])
>           ad_user.Put('userPrincipalName',user['login']+'@email.address.com')
>           ad_user.Put('DisplayName',user['last']+' '+user['first']) #fullname
>           ad_user.Put('givenName',user['first'])
>           ad_user.Put('sn',user['last'])
>           ad_user.Put('description','regular account')
>           ad_user.Put('physicalDeliveryOfficeName','office 1')
>           ad_user.Put('HomeDirectory',r'\\server1\ '[:-1]+user['login']) 
>           ad_user.Put('HomeDrive','H:')
>           ad_user.SetInfo();ad_user.GetInfo()
>           ad_user.LoginScript='login.bat'
>           ad_user.AccountDisabled=0
>           pas = raw_input("\nChoose PaSSword..:")
>           ad_user.setpassword(pas)
>           ad_user.Put('pwdLastSet',0) #-- force reset of password
>           ad_user.SetInfo()

Get hold of this:

  http://timgolden.me.uk/python/active_directory.html

and then try something like this:

<code>
import active_directory

ad = active_directory.AD ()
ou = ad.find_ou ("it") # or wherever

user = active_directory.AD_object (ou.Create ("user", "cn='tjg'")
user.sAMAccountname = "timgolden"
user.givenName = "Tim"
#
# etc.
#

#
# or
#
user.set (
  sAMAccountName = "timgolden",
  givenName = "Tim",
  # etc.
)

</code>



TJG



More information about the Python-list mailing list