简体   繁体   English

如何使用批处理脚本从文本文件创建用户并分配组?

[英]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). 同样,密码没有写在文本文件中,但是每个人的密码都是相同的(例如: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. 在此示例中,我仅给出了一个示例,该文件中有3个用户,但是该文件中也可以有100个用户来创建和分配。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建从批处理文件复制ping信息的文本文件? - How can I create a text file that copies ping info from the batch file? 如何从Shell脚本创建批处理文件 - How to create a batch file from shell script 如何在Windows批处理的for循环中从文本文件分配变量 - How to assign variables from text file in for loop of windows batch 在批处理文件中,如何将一串值分配给变量列表? - In a batch file, how can I assign a string of values to a list of variables? 是否有批处理脚本将用户添加到组高级用户? - Is there a batch script to add users to the group power users? 如何使用批处理脚本从文本文件中获取唯一字符串 - how to get a unique string from a text file using Batch script 如何批量创建多行文本文件? - How do I create a multiline text file with batch? 如何在输出重定向中使用vbscript变量从批处理脚本写入配置文件 - How can I write a config file from batch script using vbscript variables in output redirect 我如何从批处理文件调用具有2个参数的Java脚本函数并将结果返回到dos变量 - how I can call from batch file a java script function with 2 arguments and return the result to a dos variable 如何以管理员身份从批处理文件运行 powershell 脚本以加入域? - How can i run a powershell script from a batch file as admin to join a domain?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM