Vortex566 Posted January 15, 2010 Posted January 15, 2010 (edited) 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. #!/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() Edited January 15, 2010 by Vortex566 2
Hightower Posted January 15, 2010 Posted January 15, 2010 I get error on line 46: expected indented block
Hightower Posted January 15, 2010 Posted January 15, 2010 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. Thanks for this! Such a big help 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!
Vortex566 Posted January 15, 2010 Author Posted January 15, 2010 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.
davidneudorfer Posted January 10, 2012 Posted January 10, 2012 Hightower, would you mind posting your script? I also am in need of something similar.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now