‘ Part 1: Use ADO to open the Excel spreadsheet.
Dim oCN
Set oCN = CreateObject("ADODB.Connection")
oCN.Open "Excel"
Dim oRS
Set oRS = oCN.Execute("SELECT * FROM [Sheet1$]")
‘ Part 2: Use ADSI to obtain a reference to the NT domain.
Dim oDomain
Dim sPDC
sPDC = "NT4PDC"
Set oDomain =
LISTING : Bulk-users.vbs
GetObject(« WinNT:// » & sPDC)
‘ Part 3: Open an output text file to store users initial passwords.
Dim oFSO, oTS
Set oFSO = CreateObject(« Scripting.FileSystemObject »)
Set oTS = oFSO.CreateTextFile(« C:\passwords.txt »,True)
‘ Part 4: For each record in the record set, add the user, set the correct user
‘ properties, and add the user to the appropriate groups.
‘ Create the necessary variables.
Dim sUserID, sFullName, sDescription
Dim sHomeDir, sGroups, sDialIn
Dim sPassword, oUserAcct, oFolder
Dim sGroupList, iTemp, oGroup
‘ Define the base path in which to create the home directories.
Dim sHomePath, sMsg
sHomePath = « \\iridis1\c$\users\ »
‘ Go through the record set one row at a time.
Do Until oRS.EOF
‘ Get the user information from this row.
sUserID = oRS(« UserID »)
sFullName = oRS(« FullName »)
sDescription = oRS(« Description »)
sHomeDir = oRS(« HomeDirectory »)
sGroups = oRS(« Groups »)
sDialIn = oRS(« DialIn »)
‘ Make up a new password.
sPassword = Left(sUserID,2) & DatePart(« n »,Time) _
& DatePart(« y »,Date) & DatePart(« s »,Time)
‘ Create the user account.
On Error Resume Next
Set oUserAcct = oDomain.Create(« user »,sUserID)
If Err <> 0 Then
sMsg = « An error occurred creating user » _
& sUserID & vbCrLf & vbCrLf
sMsg = sMsg & « The error is: » & Err.Description
MsgBox sMsg
End If
On Error Goto 0
‘ Set account properties.
oUserAcct.SetPassword sPassword
oUserAcct.FullName = sFullName
oUserAcct.Description = sDescription
oUserAcct.HomeDirectory = sHomeDir
‘ Set RAS permission.
If sDialIn = « Y » Then
oUserAcct.RasPermissions = 9
Else
oUserAcct.RasPermissions = 1
End If
‘ Save the account.
oUserAcct.SetInfo
‘ Get a reference to the new account.
‘ This step provides a valid SID and other information.
Set oUserAcct = GetObject(« WinNT:// » & sPDC & « / » & sUserID & « ,user »)
‘ Write the password to a file.
oTS.Write sUserID & « , » & sPassword & vbCrLf
‘ Part 4A: Add the user account to groups.
‘ Use the Split function to turn the comma-separated list into an array.
sGroupList = Split(sGroups, « , »)
‘ Go through the array and add the user to each group.
For iTemp = 0 To uBound(sGroupList)
‘ Get the group.
Set oGroup = GetObject(« WinNT:// » & sPDC & « / » & sGroupList(iTemp) _
& « ,group »)
‘ Add the user account.
oGroup.Add oUserAcct.ADsPath
‘ Release the group.
Set oGroup = Nothing
Next
‘ Part 4B: Create the user s home directory.
‘ (Append the UserID to the Home Path variable).
Set oFolder = oFSO.CreateFolder(sHomePath & sUserID)
‘ Part 5: Release the user account.
Set oUserAcct = Nothing
‘ Move to the next row in the record set.
oRS.MoveNext
Loop
‘ Part 6: Final clean up and close down.
oRS.Close
oTS.Close
WScript.Echo « Passwords have been written » & « to C:\passwords.txt. »
Téléchargez cette ressource
Microsoft 365 Tenant Resilience
Face aux failles de résilience des tenants M365 (configurations, privilèges, sauvegarde). Découvrez 5 piliers pour durcir, segmenter et surveiller vos environnements afin de limiter l’impact des attaques. Prioriser vos chantiers cyber et améliorer la résilience de vos tenants Microsoft 365.
Les articles les plus consultés
- Partager vos images, vidéos, musique et imprimante avec le Groupe résidentiel
- N° 2 : Il faut supporter des langues multiples dans SharePoint Portal Server
- Cybersécurité Active Directory et les attaques de nouvelle génération
- Les 6 étapes vers un diagnostic réussi
- Afficher les icônes cachées dans la barre de notification
Les plus consultés sur iTPro.fr
- Fuites de données : la France, 2ème pays le plus touché au monde début 2026
- Nomios accélère sur la cybersécurité industrielle avec un SOC renforcé et une Factory OT immersive
- Femmes et métiers de la tech : une attractivité réelle freinée par des stéréotypes persistants
- Reprendre le contrôle de son SI : la clé d’un numérique à la fois souverain et responsable
Articles les + lus
Femmes et métiers de la tech : une attractivité réelle freinée par des stéréotypes persistants
Moderniser le développement logiciel : de la fragmentation à l’intégration
Analyse Patch Tuesday Mars 2026
Une nouvelle ère de la modernisation du mainframe
Communes, entreprises ? Non, face au RGAA 5, l’IA seule ne rendra pas vos sites accessibles
À la une de la chaîne Tech
- Femmes et métiers de la tech : une attractivité réelle freinée par des stéréotypes persistants
- Moderniser le développement logiciel : de la fragmentation à l’intégration
- Analyse Patch Tuesday Mars 2026
- Une nouvelle ère de la modernisation du mainframe
- Communes, entreprises ? Non, face au RGAA 5, l’IA seule ne rendra pas vos sites accessibles
