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 is 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.


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.


This unique ID is the one for the MailStore server.

To obtain your pkv3 key follow these steps

  1. Open MailStore Client
  2. G to Archive E-mail, create a “Microsoft Outlook” profile (just enter a fake profile name or PST name — Don’t run it, we just need it temporarily),
  3. Right click on this Microsoft Outlook profile and choose “Create Task” then “Copy Cmd Line”.
  4. Cancel and delete this profile, it’s not needed.
  5. Paste the copied text into notepad.. The output will look something like this:

“C:\Program Files (x86)\deepinvent\MailStore Server\MailStoreCmd.exe” –h=”localhost” –pkv3=”5DB7C9953119B32681C0A203D5AFBAD09EA0B7F6” –u=”admin” –pc=”jFX0SrppFNUwkKcbfYGbQ4qS” -c import-execute –id=2 –user=”admin” –verbose

You can then use the pkv3 key

–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’.


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


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


Share via
Copy link
Powered by Social Snap