> Tech > LISTING : Bulk-users.vbs

LISTING : Bulk-users.vbs

Tech - Par Renaud ROSSET - Publié le 24 juin 2010
email

‘ 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

Guide de Sécurité IA et IoT

Guide de Sécurité IA et IoT

Compte tenu de l'ampleur des changements que l'IA est susceptible d'entraîner, les organisations doivent élaborer une stratégie pour se préparer à adopter et à sécuriser l'IA. Découvrez dans ce Livre blanc Kaspersky quatre stratégies efficaces pour sécuriser l'IA et l'IoT.

Tech - Par Renaud ROSSET - Publié le 24 juin 2010