Community discussions

MikroTik App
 
Aymen1986
newbie
Topic Author
Posts: 40
Joined: Thu Jul 12, 2018 5:15 pm

script to add bulk of users to UserMan

Sat Apr 19, 2025 11:48 pm

hi there ,
i'm looking for script to add bulk of users to UserManager , i know how to add single user and assign profile to it .
any suggestions
 
User avatar
patrikg
Member
Member
Posts: 417
Joined: Thu Feb 07, 2013 6:38 pm
Location: Stockholm, Sweden

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 10:49 am

Have you consider using the api ?

With curl (Linux/Windows) for example, or with powershell with cmdlet ´Invoke-WebRequest´.
In powershell you have to use curl.exe to get curl command, so you don't get the powershell alias to cmdlet ´Invoke-WebRequest´.

Using like a csv file for example.
Last edited by patrikg on Sun Apr 20, 2025 4:54 pm, edited 1 time in total.
 
Aymen1986
newbie
Topic Author
Posts: 40
Joined: Thu Jul 12, 2018 5:15 pm

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 3:28 pm

currently i want to use simple ssh
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4862
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 4:52 pm

currently i want to use simple ssh
You're going to have to provide more details on what you're looking for and what your starting with...

i.e.
- what version of RouterOS?
- is user manager already setup and working for users, and ONLY bulk add is needed?
- do you want user manager to generate users (i.e. /user-manager/user add-batch-users)? or... you already have some list of users (like CSV) you want to add in bulk?
- do you want it run on RouterOS, or use ssh from another PC?
- etc...
 
Aymen1986
newbie
Topic Author
Posts: 40
Joined: Thu Jul 12, 2018 5:15 pm

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 6:10 pm

currently i want to use simple ssh
You're going to have to provide more details on what you're looking for and what your starting with...

i.e.
- what version of RouterOS?
RouterOS V6.49.7
- is user manager already setup and working for users, and ONLY bulk add is needed?
just bulk of users , all things are configured and worked fine
- do you want user manager to generate users (i.e. /user-manager/user add-batch-users)? or... you already have some list of users (like CSV) you want to add in bulk?
I want user manger to generate bulk of users not from csv
- do you want it run on RouterOS, or use ssh from another PC?
from winbox - etc...
 
hasinadirj
just joined
Posts: 3
Joined: Thu Dec 26, 2024 2:58 pm

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 8:01 pm

Have you consider using the api ?

With curl (Linux/Windows) for example, or with powershell with cmdlet ´Invoke-WebRequest´.
In powershell you have to use curl.exe to get curl command, so you don't get the powershell alias to cmdlet ´Invoke-WebRequest´.

Using like a csv file for example.
Good evening, I'm currently looking to use the "add-batch-user" function in mikrotik Ros v7.18 (CHR) user-man to generate users? with curl, windows powershell, or using Postman. Can you show me an example? The PUT method only works on http://ip-router/rest/user-manager/user not on http://ip-router/rest/user-manager/user/add-batch-user and POST of http://ip-router/rest/user-manager/user/ result an error of bad command. Thank you
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4862
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 8:35 pm

- what version of RouterOS?
RouterOS V6.49.7
There is no batch-add-user AFAIK in V6 — but I'm not the expert on UM under V6.

You should be able to use a for loop to add users. You'd have to adapt to your needs, but essentially something like:

:for n from=1 to=100 do={
/user-manager/user add name="user$n" ...
}

(where the $n is a number from 1 to 100 — the the to= to use less users, or from from= if you want to add more users after the first round)
Last edited by Amm0 on Mon Apr 21, 2025 12:57 am, edited 1 time in total.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4862
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 8:38 pm

The PUT method only works on http://ip-router/rest/user-manager/user not on http://ip-router/rest/user-manager/user/add-batch-user and POST of http://ip-router/rest/user-manager/user/ result an error of bad command. Thank you

You need to use POST with http://ip-router/rest/user-manager/user/add-batch-user. It will NOT work with a PUT or GET, since it's an operation. That means you need to have JSON in body with attributes for the add-batch-user.
 
hasinadirj
just joined
Posts: 3
Joined: Thu Dec 26, 2024 2:58 pm

Re: script to add bulk of users to UserMan

Sun Apr 20, 2025 8:44 pm

[/quote]
You need to use POST with http://ip-router/rest/user-manager/user/add-batch-user. It will NOT work with a PUT or GET, since it's an operation. That means you need to have JSON in body with attributes for the add-batch-user.
[/quote]

Thank you for your answer, but I always get the error "detail": "no such command", (in the screenshot)
NB: "username-length": 6,
You do not have the required permissions to view the files attached to this post.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4862
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: script to add bulk of users to UserMan

Mon Apr 21, 2025 12:53 am

The JSON in photo is wrong "username-length" & the URL is .../add-batch-users — likely BOTH are your issue.

Using CURL with 7.19beta, the following worked (*changed password/ip):
curl -k 'https://192.168.88.1/rest/user-manager/user/add-batch-users' --json `jo number-of-users=1 username-length=8` --user adminusernmame:somepassword
Again, the add-batch-users command — AFAIK — new in V7 user-manager. I do not believe it's in V6 (although don't have any V6 UM installs to check)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 13082
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: script to add bulk of users to UserMan

Tue Apr 22, 2025 11:06 am

( On v6 web interface exist "add batch" and you can download the list of generated users. )