No subject

norseman norseman at hughes.net
Tue May 12 19:17:58 CEST 2009


karlos barlos wrote:
> hello to all 
> 
> i have been using this script to add users to my active directory structure
> 
> i wise to make a loop in order for it to run for A large Number of Users 
> 
> can anyone give me some advice on the loop ??
> 
> 
> 
> 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
>   ad_user.setpassword('the password')
>   ad_user.Put('pwdLastSet',0) #-- force reset of password
>   ad_user.SetInfo()
> 
> 
> location='LDAP://OU=sales,DC=shay,DC=com'
> user={'first':'shay','last':'smith','login':'shay123'}
> add_acct(location,user)
> 
> 
> location='LDAP://OU=sales,DC=shay,DC=com'
                             DC=ron  yes?
> user={'first':'ron','last':'smith','login':'ron1267'}
> add_acct(location,user)
> 
> 
> 
> 
>       
> 
=======================================
.
.
def add_acct(location,account):
  OK



presumably you are reading from a list of names in a file
names= open(..)
Now you need a loop
for name in names:
   the location=  needs a variable in place of shay ('name' in this case)
   user=  this needs more explanation from you
          seems to be an attempt at alphabetizing
          if so:  presort the file with list of names
                or better yet
                  just read them in and sort entire list afterwards to
                  final file or python list (see python index)
   add name to listTemp
for user in list already existing:
   add user to listTemp
for user in list.Temp.index():
   copy to ListSorted
   reset first/last as needed
for user in ListSorted:
   store it someplace  (like your data file)


I suspect some of the add_.. function will need some mods, but maybe not
If 'shay123' is line number, track it in 'copy to ListSorted' section.
If the number is user id, assign it in source file.
(name id     1 pair per line, adjust read,etc to accommodate)

Today is: 20090512
no code this section

Steve



More information about the Python-list mailing list