简体   繁体   中英

How can I create users and assign group from a text file with a batch script?

First, here's an example of what the text file contains.

bob,supervisor
mary,technician
shane,user

As you may see, on the left is how the user account name would be and on the right is the name of their group they have to be assigned to. These groups are already created. Also, the password isn't written in the text file, but it would be the same for everyone (example: 123). In this example, I only gave an example with 3 users in the file, but the file could also have 100 users to create and assign in it.

I have tried a lot of different ways to make this work, but I just can't figure it out, so if someone could help me, that would be insanely useful.

如果您需要这些用户成为本地用户,并且假设您的数据位于C:\\ Data.csv中,则[未测试]

for /f "tokens=1,2 delims=," %%a in ('type "C:\Data.csv"') do (net user %%a 123 /ADD & net localgroup %%b %%a /ADD)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM