Script Center > Gallery > Active Directory > Create Active Directory User Accounts From Imported Data
TechNet Script Center logo

Welcome to the TechNet Script Center Gallery!

Each contribution is licensed to you under a License Agreement by its owner, not Microsoft. Microsoft does not guarantee the contribution or purport to grant rights to it.

Create Active Directory User Accounts From Imported Data

(Community)
Rate it:
 
 
 
 
 
Script Code
VBScript
'* description: create AD user accounts from the text file created by the export script.
'* author: Chris Pilling.
'* date: 18 June 2008.
'* I create an OU called import to create the accounts in then move the users around using dsa.msc.
'* REMEMBER to delete system generated accounts from the text file before running.
'* This script will quit if an account in the text file duplicates an existing one.
'* you will need to edit the FQDN for the UPN in the text file if your new AD is different from the
' one you exported from.   
 
Const ADS_UF_NORMAL_ACCOUNT = 512  
Dim strL
Const ForReading = 1
 
Set objRoot = GetObject("LDAP://RootDSE") 
varDomainNC = objRoot.Get("DefaultNamingContext") 
Set objDomain = GetObject("LDAP://" & varDomainNC) 
 
'* edit the line below to match your FQDN
 
Set objOU = GetObject("LDAP://ou=import,dc=local,dc=contoso,dc=com")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.OpenTextFile("d:\AD_Users_Export.txt", ForReading)
Do until ts.AtEndOfStream
strL = ts.ReadLine
spl1 = Split(strL, ",")
 
wscript.echo "samAccountName = " & (spl1(0))
wscript.echo "CN = " & (spl1(0))
wscript.echo "First Name = " & (spl1(2))
wscript.echo "Last Name = " & (spl1(3))
wscript.echo "UserPrincipalName = " & (spl1(4))
wscript.echo "display name = "  & (spl1(2)) & " " & (spl1(3))
wscript.echo "Homedrive = " & (spl1(6))
wscript.echo "HomeDirectory = " & (spl1(7))
wscript.echo "LoginScript = " & (spl1(8))
 
'* edit the line below to match your FQDN
 
Set objOU = GetObject("LDAP://ou=import,dc=local,dc=contoso,dc=com")
Set objUser = objOU.Create("User", "cn =" & (spl1(1)))
objUser.Put "displayName", (spl1(2)) & " " & (spl1(3))
objUser.Put "sAMAccountName", (spl1(0))
objUser.Put "givenName", (spl1(2))
objUser.Put "UserPrincipalName", (spl1(4))
objUser.Put "sn", (spl1(3))
objUser.Put "profilePath", (spl1(5))
objUser.Put "Homedrive", (spl1(6))
objUser.Put "HomeDirectory", (spl1(7))
objUser.Put "Scriptpath", (spl1(8))
objUser.SetInfo
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateFolder("\\srv01\users" & "\" & (spl1(0)))
Set objFile2 = objFSO.CreateFolder("\\srv01\profiles" & "\" & (spl1(0)))
 
objUser.AccountDisabled = FALSE
 
'* edit the password to suit
 
objUser.SetPassword("jmc.it")
objUser.SetInfo
 
Loop
Platforms
Windows Server 2008 R2 No
Windows Server 2008 No
Windows Server 2003 No
Windows 7 No
Windows Vista No
Windows XP No
Windows 2000 No
For online peer support, join The Official Scripting Guys Forum! To provide feedback or report bugs in sample scripts, please start a new discussion on the Discussions tab for this script.
Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
Be the first to create a discussion.