Mattermost, Inc.

Mattermost Recipe: How to process a large amount of items using the Mattermost CLI


You have a couple thousand users you need to remove from a specific channel.


  1. Get a list of the user’s email addresses, usernames, or user IDs in a text file, with one entry per line named users.txt. For example:
  1. Create this shell script and give it the name


while read id;  do
	/opt/mattermost/bin/mattermost $mattermost_cmd $id;
done <$ids_file
  1. Run the shell script with the Mattermost CLI command as the first argument and the text file as the second argument. For example:
$ ./ "channel remove teamname:channelname" users.txt


This is a really common problem for Mattermost administrators, and bash’s great scripting functionality solves it very easily. This works for any Mattermost CLI command that accepts an identifier as the final argument, such as channel archive, team add, or user deactivate


Mattermost Command Line Tools on Gist

If you have any feedback or specific questions about how to use this script please let me know!