‘ 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
Les plus consultés sur iTPro.fr
- Les agents d’IA fragilisent la sécurité : pour les sécuriser, inutile de repartir de zéro
- Yampa : innovation en IA, souveraineté et sécurité au service des DSI
- Les marchés publics peuvent-ils encore faire émerger des champions numériques français ?
- ESET accélère en France et mise sur l’IA face à la montée des cybermenaces
Articles les + lus
Computex 2026 : 5 signaux forts à retenir
La chaîne d’approvisionnement, point de rupture récurent du SI
Microsoft Build 2026 : contre-offensive des modèles maison face à OpenAI et Anthropic
Rhea1 : SiPearl allume le CPU européen le plus ambitieux pour le HPC et l’IA souveraine
Analyse Patch Tuesday Mai 2026
À la une de la chaîne Tech
- Computex 2026 : 5 signaux forts à retenir
- La chaîne d’approvisionnement, point de rupture récurent du SI
- Microsoft Build 2026 : contre-offensive des modèles maison face à OpenAI et Anthropic
- Rhea1 : SiPearl allume le CPU européen le plus ambitieux pour le HPC et l’IA souveraine
- Analyse Patch Tuesday Mai 2026
