Friday, September 14, 2012

Zimbra Bulk User Delete

One of the responsibilities I have in my environment is to manage all the user accounts in Active directory and our mail system.  We use a Zimbra mail system which is hosted for us.  If you are unfamiliar with Zimbra the quick story is that it was started up by Zimbra inc., purchased by Yahoo! in 2007 and acquired by VMware sometime between 2010 and 2011.  I am crazy in love with VMware but this is a solution I believe they could have done with out.  (Just my opinion).  :)

Zimbra is an open source solution.  There is some commercially supported version of Zimbra, but since we are having it hosted for us, I cannot speak about it.  I believe it is primarily an open source solution though.  The control panel for administration is not very helpful on an Enterprise administration level.  There is no way to bulk upload, delete or apply attributes to users.  In the Enterprise Education platform  this is a nightmare for me. 

I was working with our provider on a way to handle the bulk uploads of our student accounts.  Of course the provider will do it for me if I send them a CSV file with the accounts I need added... but I am an Enterprise Admin... I want to do it myself!  :)  

I got some instructions on how to setup a CLI utility called zmprov which is used to provision accounts on a Zimbra server.  It needs to run on a linux server.  I choose Ubuntu 12.  Once this is setup you can simply use some commands found on the zmprov wiki site to help you provision bulk uploads and deletes amongst a ton of other things.  One would have to be very careful in doing this as you can do serious damage to your accounts if you type the wrong thing.

The instructions are as follows:
-Stand up a Linux VM
-Follow these instructions to install zmprov.  (These are tailored for using a hosted zimbra)

Once that was done (after a few trial and errors), I cheated on the bulk deletion of users.  Instead of using a CSV file and importing it to the zmprov server and launching a ridiculously tailored script, I found that if you setup your CSV file correctly you could just copy and paste the context of the file into the ssh session on your zmprov server.  Here is what I did:

-Dumped a CSV file of the users from the Zimbra admin panel. 
-Removed the users I did not want to delete from the file.
-Removed all the columns of the CSV file except the email address.
-Moved the email address field to the "C" column.
-In column "A" added the command: zmprov -s <servername> -a <adminaccount> -p <password>
-In column "B" I added: da
-Saved the file as a text file.
-Opened the file in notepad and did a replace command.  Replaced , with a blank space.  Saved the file.

Now you have a txt file with the delete account command for each account.  So now each string for each account you want to delete looks like this:

zmprov -s <servername> -a <adminaccount> -p <password> da account@domain.com

Im my case I had 240 lines of this because I was delete 240 accounts.  I literally copied the entire contents of that txt file and pasted it into the zmprov ssh session and off it went!  About an hour later all 240 accounts were gone!

I suppose you could do the same thing for creating accounts by using the "ca" (create account command).

Cheers!

No comments:

Post a Comment