1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| option explicit
dim LDAPConnectString
dim Connection, InputFileName, FSO, TextFile, Count, User, Line, Cols
dim SamAccountName, CN, FirstName, LastName, UserPrincipalName
on error resume next
Const SuffixeUPN = "@labo.local"
Const CSVSeparator = ";"
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
LDAPConnectString = "LDAP://ou=Utilisateurs,dc=labo,dc=local"
Set Connection = GetObject(LDAPConnectString)
InputFileName = "IDE-01-.csv"
Count = 0
set FSO = CreateObject("Scripting.FileSystemObject")
set textFile = FSO.OpenTextFile(InputFileName,1)
Do until textFile.AtEndOfStream
Line = textfile.ReadLine
Cols = Split(Line, CSVSeparator)
Count = Count + 1
LastName = Trim(cols(0))'Nom
FirstName = Trim(cols(1))'Prenom
Pass = Trim(cols(2)) 'Mot de passe
Ou = Trim(cols(3))
SamAccountName = Lcase(LastName & Left(FirstName, 1))
Set User = Connection.Create("User", "CN=" & LastName & " " & FirstName)
User.Put "displayName", LastName & " " & FirstName
User.Put "sAMAccountName", SamAccountName
User.Put "givenName", FirstName
User.Put "sn", LastName
User.Put "UserPrincipalName", SamAccountName & suffixeUPN
User.SetInfo
User.AccountDisabled = false
User.SetPassword (Pass)
User.Put "userAccountControl", ADS_UF_DONT_EXPIRE_PASSWD
Const UAC = 544
User.SetInfo
Loop
wscript.echo "Opération Terminée. " & Count & " utilisateurs importés."
textFile.close
set Connection = nothing
set FSO = nothing
set textFile = nothing |
Partager