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!



How would I go about using this script to delete thousands of archived channels? I have a .txt file with a list of each channel that was pulled using CLI so would I change the first argument to “channel remove” channels.txt? When I try to delete each channel individually I get a “Unable to find channel” even though it is pulled from the CLI verbatim so I’m worried that it will throw the same error with the script. Thanks in advance for your help!