DSADD用户通过Server 2008上的CSV

从今天上午开始,我一直在尝试将100个用户添加到Server 2008上的新AD中。

我在excel文件中的字段是:

姓,名,用户名,密码,组(NewUser,PowerUser,SuperUser),邮箱地址(不交换信息只是为了方便用户)。

以下是脚本,我从某人的网站上复制build议:

脚本代码:

---[AddUser.cmd]---- @echo off setlocal :: *** csv-File with the name, first name, and user name: set UserFile=C:\Users\Administrator\Desktop\scriptusers\users1.csv :: *** Distinguished Name of the container to add the new user to: set UsersDN=OU=newcompany,DC=domain,DC=com for /f "tokens=1-4 delims=," %%a in ('type "%UserFile%"') do ( set LastName=%%a set FirstName=%%b set NewUser=%%c set Password=%%d call :process ) goto :leave :process set UPN=%NewUser%@%UserDNSDomain% set DisplayName=%LastName%, %FirstName% set NewUserDN=CN=%NewUser%,%UsersDN% set Password=password echo You are about to create a new user with the following properties: echo. echo Username: %NewUser% echo Display name: %DisplayName% echo UPN: %UPN% echo OU: %UsersDN% echo. echo Hit ^<ctrl-c^> to stop, any other key to create the user. pause >NUL echo. :: *** Test mode: Remove the "ECHO" in front of the following line to run the script for real: dsadd user "%NewUserDN%" -samid %NewUser% -upn %UPN% -fn "%FirstName%" -ln "%LastName%" -display "%DisplayName%" -pwd "%Password%" -desc "%DisplayName%" -mustchpwd yes -disabled no :leave 

现在,我把excel文件导出到csv,根据我的喜好编辑脚本,但是当我运行它时,它只添加了一个用户(在csv上的第一个用户),否则会给密码的复杂性带来错误。 我改变了脚本中的密码足够复杂,但没有运气。

如果有人能让我知道如何一步一步地做到这一点,我将非常感激。 我是一个脚本和理解脚本的新手。

感谢和问候AerAps

你可以使用PowerShell。 这使得这一点不那么痛苦,脚本更直接。 我不记得它是否默认包含在Server 2008中。 如果没有,这是一个function,你可以安装服务器pipe理器。

它会自动为你导入csv。 所有你需要做的是确保CSV具有列标题。 看一个简单的例子,下面的代码。 您可以在下面的dsadd命令上展开以匹配您所需的内容。

 $inputFile = Import-CSV <insert filepath here> foreach($line in $inputFile) { dsadd user -samid $line.Username -pwd $line.Password } 

尝试使用csvde, 这里很好的资源,这可能是这个工作的最佳工具。

您可能考虑的另一个选项:

我几年前写的一个工具,可以将用户从Excel导入到AD中 。