Zimbra: Batch User creation using SOAP

It was a long time ago that I hadn’t written a post.
I’m taking advantage to have some spare time to finally make it.

I’d come across the article of Jorge allowing to create demo accounts on Zimbra using a script.
Apart from the fact that Zimbra already offers this option by default:

zmprov createBulkAccounts (cabulk) {domain} {namemask} {number of accounts to create}

going through an intermediate file and having to modify the script to adapt it makes the solution, in my opinion, painful.

You will tell me, that the command provided by Zimbra does the job, yes, but it must be executed from the Zimbra server.
To solve this, I created a script allowing to perform the same manipulation, but from any computer having curl installed and above all using SOAP, so no need to load Zimbra user environment variables.

So in terms of performance, that’s how it works:
Zimbra command (executed from Zimbra server)

time zmprov createBulkAccounts domain.tld test 50
3c832f41-8f94-4b2f-b989-7ef40156f2f4
...
20a09f7a-172c-4ac0-9df0-f568444ecfe4
51ff0d62-54d0-4bcd-8cd1-22db50bbbe41

real    0m6.256s
user    0m5.296s
sys     0m0.126s

Jorge script (executed from Zimbra server)

time zmprov -f /tmp/userlist.zmp
prov> b83aef83-98e2-470f-957e-7e144bc9c4da
...
prov> a93cb901-ce8a-4351-8a53-b39772797068
prov>
real    0m6.259s
user    0m5.529s
sys     0m0.188s

Soap Script (executed from Zimbra server)

time zimbra_soap_demo_account.sh -a zimbra_admin -s zimbra_url -u test -d domain.tld -c 50
Enter Zimbra Admin Password
Creating Account test0@domain.tld
Creating Account test1@domain.tld
...
Creating Account test49@domain.tld

real    0m4.804s
user    0m0.492s
sys     0m0.090s

\o/ 2 seconds won on 50 accounts !

The big advantage is that it’s portable and you can create your accounts from anywhere:)
An example from my computer via an internet connection that deserves to be upgraded (4 Mbps):

time zimbra_soap_demo_account.sh -a zimbra_admin -s zimbra_url-u test -d domain.tld -c 50
Enter Zimbra Admin Password
Creating Account test0@domain.tld
Creating Account test1@domain.tld
...
Creating Account test49@domain.tld
real 21.799
user 1.43s 
system 0.75s 

You must also take into account the time to type your password 😉
You will find the script on my github.

Leave a Reply

Your email address will not be published. Required fields are marked *