Crear cuentas de usuario en Directorio Activo a partir de un fichero

Los campos deberán estar separados por comas.

 

'* 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

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s