This is a script written in python that will add user accounts in AD into Zimbra. It uses the LDAP module for python so this is needed before you run the script. This script allows you to define the class of service you wish to use.
If you have any questions I will do my best to answer them.
Code:#!/usr/bin/python import ldap,sys,os,time baseDN = "ou=, dc=example, dc=com" filter = "sn=*" pathtozmprov="/opt/zimbra/bin/zmprov" f = os.popen(pathtozmprov +' -l gaa ') zmprovgaa =  zmprovgaa = f.readlines() try: l = ldap.initialize("path to ldap server") l.simple_bind_s("cn=user, dc=example,dc=com","password") #User with rights to bind to LDAP print "Successfully bound to server.\n" result = l.search_s(baseDN, ldap.SCOPE_SUBTREE,filter) for (dn, vals) in result: accountname = vals['sAMAccountName'].lower() mail = vals['mail'] disN = vals['displayName'] try: sirname = vals['sn'].lower() except: sirname = vals['sAMAccountName'].lower() try: givenname = vals['givenName'] except: givenname = vals['sAMAccountName'].lower() initial = givenname[:1].upper() sirname = sirname.replace(' ', '') sirname = sirname.replace('\'', '') sirname = sirname.replace('-', '') sirname = sirname.capitalize() name = "'" + givenname + " " + sirname +"'" accountname = accountname + "@" + domain password = " \'\' " sys.stdout.flush() if mail +"\n" not in zmprovgaa: print accountname," exists in active directory but not in zimbra, the account is being created\n" time.sleep(1) os.system(pathtozmprov + ' ca %s %s displayName %s givenName %s sn %s ' % (mail,password,name,givenname,sirname)) print "The following account was added " + mail + "\n" cos = raw_input ('Which Class of Service? ') os.system(pathtozmprov + ' sac %s %s ' % (accountname,cos)) except ldap.LDAPError, error_message: print error_message l.unbind_s()
Last edited by Vortex566; 15th January 2010 at 11:44 AM.
I get error on line 46: expected indented block
I've tweaked it to suit a little. First I've made a script that adds all my student accounts to the student COS (based on they all begin with two numbers). I have that running now.
Then I have another script which actually asks "Do you want to create this account [y/n]" as we have some accounts in AD that are exam/temp accounts which we do not want mailboxes setting up for.
Once again, thanks!
No problem glad it helped... I myself based it on a script I found on here. I had to mod it a lot to get it to work but I got there in the end.
I hope to add more features when I get the time.
Once again I am glad it helped.
Hightower, would you mind posting your script? I also am in need of something similar.
There are currently 1 users browsing this thread. (0 members and 1 guests)