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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
Dim fs,a,b,fso,c,OS,d,e,f,g,h,r,sMsg,oFSO,oTS,FicPassword,Commandline,Commandline1,Commandline2,Commandline3,wshShell,RepPerso,RepProfil
dim strStudent,strNom,strPrenom,strHomeDir,strGroupes,strMDP,sHomePath,oFolder,strUAC,strProfilePath,strScriptPath,strHomeDrive
dim strEtude,strGroup,objContainer,objGroup,objStudent,strUPN,strSAM,sGroupList,iTemp,oGroup,sProfilPath,strHomeDirectory
r=""
while r=""
r=inputbox("Entrez le nom du fichier des utilisateurs à créer (sans extension) : ")
wend
set wshShell = CreateObject("Wscript.Shell")
set e=wshShell
set f=wshShell
set g=wshShell
set h=wshShell
Set fs = CreateObject("Scripting.FileSystemObject")
Set b = fs.openTextFile(r&"T:\Fichiers Usagers\mathieu.bes\Public\Réseaux\Scripts\listuser.csv") 'Ouvre le fichier dans lequel il y a la liste des utilisateurs
FicPassword = r & "C:\test\Password.txt" 'On donne à FicPassword le nom du fichier où sera stocké les mots de passe
set oFSO=CreateObject("Scripting.FileSystemObject")
set oTS=oFSO.CreateTextFile(FicPassword,True) 'Création d un fichier où est stocké tous les mots de passe
strEtude = "ou=Eleve,dc=...................................."
strGroup = "ou=Global,ou=Groupes,dc=................................................................................."
set objContainer=GetObject("LDAP://" & strEtude)
set objGroup = GetObject("LDAP://" & strGroup)
sHomePath="\\tandem-mail\Utilisateurs$\"
sProfilPath="\\tandem-mail\Profils$\"
i = 0
fin = False
While b.AtEndOfStream=false
i = i + 1
a=split(b.readline,";")
select case a(2)
case "Directeur"
a(2)="Glo Directeur"
case "Participant"
a(2)="Glo Participant"
case "Permanents"
a(2)="Glo Permanents"
case "Techniciens"
a(2)="Glo Techniciens"
case "........."
a(2)="Glo ..............."
case Else
a(2)="ERROR"
end select
strStudent=a(0) & " " & a(1) 'Donne le nom complet de l utilisateur
strNom=a(0)
strPrenom=a(1)
strGroupes=a(2)
strHomeDir=left(a(1),1)&a(0) 'Création du nom du répertoire personnel
strMDP=LCase(left(a(1),1)&left(a(0),1)&left(a(1),1)&left(a(0),1)&left(a(1),1)&left(a(0),1)) 'Création du mot de passe on peut le changer ici c est la première lettre du prénom et la première lettre du nom
strUPN=LCase(strHomeDir)&"@tandem.local" 'nom de domaine
strSAM=LCase(strHomeDir)
strUAC="512" 'Permet d'activer le compte
strProfilePath=sProfilPath&strHomeDir 'Création du nom pour le répertoire du profil de l'utilisateur
strScriptPath="logon.cmd" 'Script de commande WindowsNT qui fabrique le lecteur réseau
strhomedrive="z" 'Création d'un lecteur logique
strhomeDirectory=sHomePath&strHomeDir 'Nom du répertoire pour le lecteur logique
on error resume next
set objStudent=objContainer.Create("User", "cn=" & strStudent) 'Création des propriétés du compte de l utilisteur dans Active Directory
objStudent.Put "displayname",strStudent
objStudent.Put "givenName",strPrenom
objStudent.Put "sn",strNom
objStudent.Put "userPrincipalName",strUPN
objStudent.Put "sAMAccountName",strSAM
objStudent.Put "userAccountControl",strUAC
objStudent.Put "ProfilePath",strProfilePath
objStudent.Put "scriptPath",strScriptPath
objStudent.Put "homeDrive",strhomedrive
objStudent.Put "homeDirectory",strhomeDirectory
objStudent.SetInfo
set objStudent = GetObject("WinNT://" & objContainer & "/" & strStudent &",User")
objStudent.SetPassword strMDP
oTS.Write strStudent & ","&strMDP & vbCrLf
oFolder=fs.CreateFolder(sHomePath & strHomeDir)
oFolder=fs.CreateFolder(sProfilPath & strHomeDir)
RepPerso=sHomePath & strHomedir
RepProfil=sProfilpath & strHomeDir
CommandLine="cacls " & RepPerso & " /T /E /P " & strSAM &":C" 'Donne le droit modifier à l utilisateur sur son répertoire perso
e.Run CommandLine, 1, True
Commandline1="cacls " & RepProfil & " /T /E /P " & strSAM &":C" 'Donne le droit modifier à l utilisateur sur le répertoire où est stocké son profil
f.Run CommandLine1, 1, True
Commandline2="cacls " & RepPerso & " /T /E /P Administrateurs:F" 'Donne le droit Contrôle total au groupe Administrateur de ton domaine
g.Run CommandLine2, 1, True
Commandline3="cacls " & RepPerso & " /T /E /P Glo Permanents:C" 'Donne les droits modifier à un autre groupe si celui-ci souhaite regarder ce que contient les répertoires personnels des utilisateurs
h.Run CommandLine3, 1, True
set oGroup=objGroup.Create("Group","cn="&strGroupes) 'Ajoute l'utilisateur dans son groupe
oGroup.Add objStudent.AdsPath
set oGroup=Nothing
objStudent.setInfo
set objStudent=Nothing
Wend
Wscript.Echo "Les mots de passe des " & i & " utilisateurs ont été écrit dans " & FicPassword 'Ceci permet de voir le nombre d utilisateurs créé et confirme que la création est terminée |
Partager