使用 .CSV 导入将批量用户添加到 Active Directory?

发布于 2024-11-07 18:46:35 字数 238 浏览 0 评论 0 原文

您好,感谢您查看我的问题。

我是 AD 新手,需要帮助将批量用户导入到 AD。

这是我想要导入的 csv 的链接;不用担心,这都是随机数据,没有存储任何个人信息。

http://www.mediafire.com/?s2j37lsps83o86s

谢谢!

Hello and thanks for looking at my Problem.

I am new to AD and need help importing bulk users to AD.

Here is a link to the csv i wish to import; dont worry, it is all random data and there is no personal information stored.

http://www.mediafire.com/?s2j37lsps83o86s

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

和影子一齐双人舞 2024-11-14 18:46:35

更新:

使用 PowerShell 批量用户 CSV 导入:http://www.morgantechspace.com/2014/04/Create-Bulk-AD-Users-from-CSV-using-Powershell-Script.html

VBScript:

' CreateBulkADUsersFromCSVFile.vbs
' Sample VBScript to create a AD Users from CSV file .
' Author: http://www.morgantechspace.com/
' ------------------------------------------------------' 
Option Explicit 

' Variables needed for LDAP connection 
Dim objRootLDAP 
Dim objContainer 

' Variables needed for CSV File Information
Dim varFileName
Dim objFSO
Dim objFile

' Holding variables for user information import from CSV file 
Dim varSamAccountName,varFirstName,varLastName
Dim newUserFields 

Dim objNewUser 
Dim varDomain 

Const ForReading = 1

' Modify this name to match your company's AD domain 
varDomain="workdomain.local" 

' Create a connection to the Active Directory Users container. 
Set objRootLDAP = GetObject("LDAP://rootDSE") 

' You can give your own OU like LDAP://OU=TestOU instead of LDAP://cn=Users
Set objContainer = GetObject("LDAP://cn=Users," & objRootLDAP.Get("defaultNamingContext")) 

' Specify the csv file full path.
varFileName = "C:\Users\Administrator\Desktop\NewUsers.csv"

' Open the file for reading.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(varFileName, ForReading)

' Read the first line - csv columns -not needed for our proceess
objFile.ReadLine

' Skip the error while creating new user...(i.e- user already exists)
on error resume next

' Read the file and create new user.
Do Until objFile.AtEndOfStream
    ' Splits prioperty values.
    newUserFields = Split(objFile.ReadLine,",")
    varSamAccountName = newUserFields(0)
    varFirstName = newUserFields(1) 
    varLastName = newUserFields(2) 


' Create new User account 
Set objNewUser = objContainer.Create("User","cn="&varFirstName&" "&varLastName) 

objNewUser.put "sAMAccountName",lcase(varSamAccountName) 
objNewUser.put "givenName",varFirstName 
objNewUser.put "sn",varLastName 
objNewUser.put "UserPrincipalName",lcase(varSamAccountName)&"@"&varDomain 
objNewUser.put "DisplayName",varFirstName&" "&varLastName 
objNewUser.put "name",lcase(varSamAccountName) 
objNewUser.put "description","This user was created from csv file using vbscript"

objNewUser.SetInfo 
objNewUser.Put "pwdLastSet", 0 

' Enable the user account 
objNewUser.AccountDisabled = FALSE
objNewUser.SetInfo 
Loop

MsgBox("Active Directory users created successfully from CSV file using VBScript.")

WScript.Quit  

Updated :

Bulk Users CSV Import with PowerShell : http://www.morgantechspace.com/2014/04/Create-Bulk-AD-Users-from-CSV-using-Powershell-Script.html

VBScript :

' CreateBulkADUsersFromCSVFile.vbs
' Sample VBScript to create a AD Users from CSV file .
' Author: http://www.morgantechspace.com/
' ------------------------------------------------------' 
Option Explicit 

' Variables needed for LDAP connection 
Dim objRootLDAP 
Dim objContainer 

' Variables needed for CSV File Information
Dim varFileName
Dim objFSO
Dim objFile

' Holding variables for user information import from CSV file 
Dim varSamAccountName,varFirstName,varLastName
Dim newUserFields 

Dim objNewUser 
Dim varDomain 

Const ForReading = 1

' Modify this name to match your company's AD domain 
varDomain="workdomain.local" 

' Create a connection to the Active Directory Users container. 
Set objRootLDAP = GetObject("LDAP://rootDSE") 

' You can give your own OU like LDAP://OU=TestOU instead of LDAP://cn=Users
Set objContainer = GetObject("LDAP://cn=Users," & objRootLDAP.Get("defaultNamingContext")) 

' Specify the csv file full path.
varFileName = "C:\Users\Administrator\Desktop\NewUsers.csv"

' Open the file for reading.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(varFileName, ForReading)

' Read the first line - csv columns -not needed for our proceess
objFile.ReadLine

' Skip the error while creating new user...(i.e- user already exists)
on error resume next

' Read the file and create new user.
Do Until objFile.AtEndOfStream
    ' Splits prioperty values.
    newUserFields = Split(objFile.ReadLine,",")
    varSamAccountName = newUserFields(0)
    varFirstName = newUserFields(1) 
    varLastName = newUserFields(2) 


' Create new User account 
Set objNewUser = objContainer.Create("User","cn="&varFirstName&" "&varLastName) 

objNewUser.put "sAMAccountName",lcase(varSamAccountName) 
objNewUser.put "givenName",varFirstName 
objNewUser.put "sn",varLastName 
objNewUser.put "UserPrincipalName",lcase(varSamAccountName)&"@"&varDomain 
objNewUser.put "DisplayName",varFirstName&" "&varLastName 
objNewUser.put "name",lcase(varSamAccountName) 
objNewUser.put "description","This user was created from csv file using vbscript"

objNewUser.SetInfo 
objNewUser.Put "pwdLastSet", 0 

' Enable the user account 
objNewUser.AccountDisabled = FALSE
objNewUser.SetInfo 
Loop

MsgBox("Active Directory users created successfully from CSV file using VBScript.")

WScript.Quit  
九命猫 2024-11-14 18:46:35

您所要求的是一个脚本/程序以自动方式处理此任务。仅仅进来并要求人们为你做你的工作是不受欢迎的,因为这个网站真正关注的是那些在他们正在做的事情上需要帮助的人。

理想情况下,您可以将您的问题与您正在使用的代码一起发布,以及出了什么问题;不仅仅是要求别人为你编写程序。

我怀疑如果您不更改问题,它将/应该被删除。

What you are asking for is a script/program to handle this task in an automated manner. It is frowned upon to just come in and ask people to do your work for you as this site is really focused on people that need help with something they are doing.

Ideally you would post your question with the code you are working from, and what is going wrong; not just ask someone to write a program for you.

I suspect that if you don't change the question, it will/should be deleted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文