Batch file for adding MailStore users in bulk

MailStore batch file for adding userDepending upon on the design of your network, it may not always be possible to let MailStore Server automatically synchronise its list of user accounts with your Active Directory.

If that’s the case, you way well find the alternative is to add users manually.

For smaller number of users this isn’t an issue, however if you have hundreds to enter and update periodically, you may quickly find yourself thinking there are better ways to be spending your time!

Enter MailStore’s API which enables the administration of a wide range of tasks via its management shell.

A list of commands supported by the MailStore management shell are available under ‘Administrative Tools > Miscellaneous > Management Shell’.

Simply type ‘help’ to list them and you’ll see the below:

You can run any command in this list manually from the management shell but you’re restricted to one at a time, which is where creating a script is useful.

In order to batch a set of commands like the one to create users we can write a Windows batch file to call the commands directly one after another. When Working with MailStore batch files we are actually calling a specific MailStore executable named ‘MailStoreCmd.exe

This executable is located within the MailStore installation folder usually ‘C:\Program Files\deepinvent\MailStore Server\MailStoreCmd.exe’

My example of the batch file for adding users

To run a specific management command, for example, ‘CreateUser‘  we can construct a windows command in the following format…

“C:\Program Files\deepinvent\MailStore Server\MailStoreCmd.exe” –h=”localhost” –pkv3=”c2:3d:b3:ce:fg:ca:b2:23″ –u=”admin” –p=”admin”  -c CreateUser –userName=fred.bloggs –privileges=login –fullName “Fred Bloggs” –password= “password123”

The batch file explained

So let me step through each part of this command line to help explain what is happening here.

The command starts with..

“C:\Program Files\deepinvent\MailStore Server\MailStoreCmd.exe”

This is the path to the MailStorecmd.exe executable, the quotes are needed due to the space in the path. Please note if you have installed MailStore to a different drive you may have a different path to your MailStore Server folder.

–h=”localhost”

Next we define which MailStore server we wish to control. I recommend executing the command locally on the actual MailStore server. Therefore we are simple connecting to the MailStore server using ‘localhost’. I have seen commands fail if you try to use the server name here so stick to ‘localhost’ whenever possible.

–pkv3=”c2:3d:b3:ce:fg:ca:b2:23″

This unique ID is the one for the MailStore server. You can insert the correct ID for you own server here but this isn’t actually necessary, so you can use the one in the example above to save time if you like.

–u=”admin” –p=”admin” 

Next we need to add the valid MailStore server Administrator username and password used to log into the MailStore client (default is ‘admin:admin’).

From now on we’re defining the actual MailStore command we wish to run and any parameters it requires.

 -c CreateUser

‘-c’ is the switch to run a command and in this example the MailStore management command we are running is called ‘CreateUser’.

–userName=fred.bloggs

Create a new user called “fred.bloggs” (please note this field must all be in lowercase).

–privileges=login

Give this user login only privileges…

–fullName “Fred Bloggs”

Assign the account a full name of “Fred Bloggs”…

–password= “password123”

And finally assign the account a password of “password123”.

The possibilities are endless!

So now that you can see how we can create a single user from the Windows command line hopefully it’s evident that it’s only a simple step further to use this format to create a script that simply repeats this command customised for each user one after another.

There are also many other options that can be defined within the CreateUser command – a full list of these can be found on the MailStore Server Administration API Commands page.

Calling all coders

A nice next step would be including the ability to automatically read a populated csv file containing user information to make it even easier to import large numbers of users with a range of parameters.

Whether my expertise can stretch to that I’m not sure so if you’re a bit of a scripting expert, please feel free to make yourself known!

Hope that was useful – until the next time! As always, please leave any comments or questions below.

MDaemon webinar sign-up

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

Zen Software logo       Try any of our software completely free for 30-days:

MDaemon email server  |   BackupAssist   |   MailStore email archiver

Let us know what you think....

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s