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'][0].lower() mail = vals['mail'][0] disN = vals['displayName'][0] try: sirname = vals['sn'][0].lower() except: sirname = vals['sAMAccountName'][0].lower() try: givenname = vals['givenName'][0] except: givenname = vals['sAMAccountName'][0].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()