Code : Tout sélectionner
#include <Excel.au3>
#include <AD.au3>
#include <RecFileListToArray.au3>
#include <Array.au3>
$fin = 0
$recherche = _RecFileListToArray("D:\USERS\Nouvelles Demandes\","*.xls", 0, 0)
For $k = 1 To UBound($recherche) - 1
ConsoleWrite($recherche[$k] & @CRLF)
$nb_ligne = 0
If not FileExists("D:\USERS\Nouvelles Demandes\" & $recherche[$k]) = 1 Then
msgbox(64,"ERREUR","Le fichier test.xls n'est pas présent dans")
Else
ProcessClose("Excel.exe")
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = 0
$oExcel.WorkBooks.Open("D:\USERS\Nouvelles Demandes\" & $recherche[$k])
For $j = 1 to 14 step 1
if ($oExcel.ActiveSheet.Cells(1+$j,1).value > " ") Then
$nb_ligne += 1
EndIf
Next
For $i = 1 to $nb_ligne step 1
$statut = $oExcel.Activesheet.Cells(1+$i,1).Value
$nom = $oExcel.Activesheet.Cells(1+$i,2).Value
$prenom = $oExcel.Activesheet.Cells(1+$i,3).Value
$matricule = $oExcel.Activesheet.Cells(1+$i,4).Value
$fonction = $oExcel.Activesheet.Cells(1+$i,5).Value
$service = $oExcel.Activesheet.Cells(1+$i, 6).Value
$societe = $oExcel.Activesheet.Cells(1+$i, 7).Value
$datefin = $oExcel.Activesheet.Cells(1+$i, 11).Value
ConsoleWrite($datefin & @CRLF)
$datefinldap = ($datefin + 11644473600)*10000000
ConsoleWrite($datefinldap & @CRLF)
$ncomplet = $prenom&" "&$nom
$upn = StringUpper(StringLeft($prenom, 1))& StringUpper(StringLeft($nom, 7))
if (($statut = "CDI") OR ($statut = "CDD") OR ($statut = "APPRENTI")) Then
$ou = 'OU=INT,OU=TEST,OU=Users,OU=Salindres,DC=axens,DC=local'
desc()
else
if ($statut = "ETV") Then
$ou = 'OU=ETV,OU=EXT,OU=TEST,OU=Users,OU=Salindres,DC=axens,DC=local'
desc()
ElseIf ($statut = "INTERIM") Then
$ou = 'OU=INTERIM,OU=EXT,OU=TEST,OU=Users,OU=Salindres,DC=axens,DC=local'
desc()
Else
$ou = 'OU=STAG,OU=EXT,OU=TEST,OU=Users,OU=Salindres,DC=axens,DC=local'
desc()
EndIf
EndIf
func desc()
_AD_Open()
$iValue = _AD_CreateUser($ou, $upn, $ncomplet)
If $iValue = 1 Then
$fin = $fin + 1
MsgBox(64, "Création du compte de '"&$ncomplet&"'", "L'utilisateur '" & $ncomplet & "' a été crée avec succés est dans l'OU '" & $ou,5)
$iValue = _AD_ModifyAttribute($upn, "givenName", $prenom)
$iValue = _AD_ModifyAttribute($upn, "sn", $nom)
$iValue = _AD_ModifyAttribute($upn, "displayName", $ncomplet)
$iValue = _AD_ModifyAttribute($upn, "l", "Salindres")
$iValue = _AD_ModifyAttribute($upn, "streetAddress", "Usine de Salindres, Avenue Jean Moulin")
$iValue = _AD_ModifyAttribute($upn, "PostalCode", "30340")
$iValue = _AD_ModifyAttribute($upn, "profilepath", "\\SALNT11\PROFILS$\" & $upn)
$iValue = _AD_ModifyAttribute($upn, "employeeID", $matricule)
$iValue = _AD_ModifyAttribute($upn, "Homedrive", "U:")
$iValue = _AD_ModifyAttribute($upn, "homedirectory", "\\SALNAS02\DATA\USERS\" & $upn)
$iValue = _AD_ModifyAttribute($upn, "scriptPath", "logonsalusr.vbs")
$iValue = _AD_ModifyAttribute($upn, "title", $fonction)
$iValue = _AD_ModifyAttribute($upn, "department", $service)
$iValue = _AD_SetPassword($upn, StringUpper(StringLeft($prenom, 1))&StringLower(StringLeft($nom, 1))&"123456")
Run(@ComSpec & " /c " & 'dsmod user "CN='& $ncomplet &","& $ou &'" -mustchpwd yes', "", @SW_HIDE)
if (($statut = "CDI") OR ($statut = "CDD") OR ($statut = "APPRENTI")) Then
$iValue = _AD_ModifyAttribute($upn, "employeeType", "INTERNE")
$iValue = _AD_ModifyAttribute($upn, "company", "Axens")
$iValue = _AD_ModifyAttribute($upn, "mail", $prenom & "." & $nom & "@axens.net")
if $statut = "CDI" Then
$iValue = _AD_ModifyAttribute($upn, "accountExpires", "0")
Else
ConsoleWrite($datefinldap & @CRLF)
$iValue = _AD_ModifyAttribute($upn, "accountExpires", $datefinldap)
EndIf
Else
$iValue = _AD_ModifyAttribute($upn, "employeeType", "EXTERNE")
$iValue = _AD_ModifyAttribute($upn, "company", $societe)
$iValue = _AD_ModifyAttribute($upn, "mail", $prenom & "." & $nom & ".pro@axens.net")
$iValue = _AD_ModifyAttribute($upn, "accountExpires", "130840704000000000")
ConsoleWrite($datefinldap & @CRLF)
EndIf
ElseIf @error = 1 Then
MsgBox(64, "Création du compte de '"&$ncomplet&"'", "L'utilisateur '" & $ncomplet & "' est déja existant",5)
Else
MsgBox(64, "Création du compte de '"&$ncomplet&"'", "Retour code erreur '" & @error & "' venant de l'Active Directory")
EndIf
_AD_Close()
endfunc
Next
EndIf
ProcessClose("Excel.exe")
FileMove("D:\USERS\Nouvelles Demandes\" & $recherche[$k], "D:\USERS\Demandes Validées\" & $recherche[$k])
Next
msgbox(0,"Fin","La création est terminée avec "&$fin&" compte(s) créé(s)",5)