Dans le cadre d'un changement de serveur avec un DNS endommagé et une AD mal configurée, j'ai fait ce programme afin d'importer les comptes utilisateurs depuis un fichier CSV.
Un prochain programme suivra pour les groupes.
► Afficher le texte
Code : Tout sélectionner
#cs ----------------------------------------------------------------------------
Version : 1.0
Auteur : Christophe
Script Function : Création des utilisateurs dans une OU existante
A partir de ; http://technet.microsoft.com/fr-fr/library/cc731279(WS.10).aspx
#ce
Dim $domaine, $OU, $prenom, $nom, $login, $description, $bureau, $homedir, $drive, $script, $pwd
Dim $fichier = @ScriptDir & "\comptead.csv"
Dim $file, $ligne, $array
If not FileExists($fichier) = 1 Then
msgbox(64,"ERREUR","Le fichier comptead.csv n'est pas présent dans "&@ScriptDir)
Exit
EndIf
$file = FileOpen($fichier,0)
While 1
$ligne = FileReadLine($file)
If @error = -1 Then ExitLoop
$array = StringSplit($ligne, ';', 1)
$domaine = $array[ 1]
$OU = $array[ 2]
$prenom = $array[ 3]
$nom = $array[ 4]
$login = $array[ 5]
$description = $array[ 6]
$bureau = $array[ 7]
$homedir = $array[ 8]
$drive = $array[ 9]
$script = $array[10]
$pwd = $array[11]
If $domaine="" Then Exit
If $domaine<>"$domaine" Then
_AddUser( $domaine, $OU, $prenom, $nom, $login, $description, $bureau, $homedir, $drive, $script, $pwd )
EndIf
WEnd
FileClose($file)
Func _AddUser( $domaine, $OU, $prenom, $nom, $login, $description, $bureau, $homedir, $drive, $script, $pwd )
Dim $ldap = ""
$ldap &= 'dsadd user cn="'&$login&',OU='&$OU&'" '
$ldap &= '-fn '&$prenom&' -ln '&$nom&' -display "'&$prenom&' '&$nom&'" -desc "'&$description&'" -office "'&$bureau&'" '
;~ $ldap &= '-dept departement -company compagnie -title titre '
$ldap &= '-upn '&$login&'@'&$domaine&' '
$ldap &= '-hmdir '&$homedir&' -hmdrv '&$drive&' -loscr "'&$script&'" '
$ldap &= '-pwd "'&$pwd&'" -mustchpwd no -canchpwd no -pwdneverexpires yes'
Run(@ComSpec & " /c " & $ldap, "", @SW_HIDE)
EndFunc ; ==> _AddUser
Pièce jointe le fichier CSV pour l'import