LISTING 1: Bulk-users.vbs ' 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 = 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."