Problem with Addusers Script

Tech-Archive recommends: Speed Up your PC by fixing your registry



Hello,

I just started at a school district as the network manager, the
previous admin had the following script that adds users to AD, sets up
home directory's and shares them out.

I wanted to add the ability for them to be added to the correct groups
within the script so I added the ***Add users to the xxx group****
section at the bottom.

This part works great, but only when there is one line in the delimited
text file we use as the source file. As soon as I put 2 or more user's
in the input file, it will add only the first member to the group and
will not add any others, everything else works fine in the script.

I did also try this script on a windows2000 server and it did the same
thing, so I dont think its because of windows 2003...

Any help would be appriciated...

Regards,
Jason

************************************************************************************************************
**********************************************
' User creation Script
'
' Input file format:
'
' Username:First:Last:Password
'************************************************

Option Explicit
Const ForReading = 1, ForWriting = 2

'*************************************************
'Declare the Variables
'*************************************************

Dim adsDomain, adsUser, fso, tsInputFile, strLine, arrInput,ObjOU
Dim fldUserHomedir, wshShell, ShareRem, DomainAddr,
MercuryFile,ObjGroup
Dim ServerName, HomePath, ProfilePath, MailPath, DataDrive, CopyTo,
CopyFrom
Dim UName, FrName, LName, FName, PWord, THold, CreateMailDir,
CreateProfilePath


'**************************************************
'Set up where the server and AD are
'**************************************************

Set adsDomain = GetObject("LDAP://cn=users,dc=fhs_svr";)
DomainAddr = "@domainname"
ServerName = "\\ourservername"
DataDrive = "e:"
HomePath = "\home\2007\"

Set fso = CreateObject("Scripting.FileSystemObject")

'**********************************************************************
'Open the text file as a text stream for reading.
'Don't create a file if users-to-create.txt doesn't exist
'**********************************************************************
Set tsInputFile = fso.OpenTextFile("Users.txt", ForReading, False)

'**********************************************************************
'Execute the lines inside the loop, even though you're not at the end
'of the file
'**********************************************************************
While Not tsInputFile.AtEndOfStream

PWord = ""
'**********************************************************************
'Read a line, and use the Split function to split the data set into
'its separate parts
'**********************************************************************
strLine = tsInputFile.ReadLine
arrInput = Split(strLine, ":")

'**********************************
' Grab the Username
'**********************************
UName = arrInput(0)

'**********************************************************************
' Grab the Frst and Last name and capilize and generate the full name
'**********************************************************************

THold = LCase(arrInput(1))
FrName = UCase(Left(Thold, 1)) & right(Thold, Len(THold) - 1)

THold = LCase(arrInput(2))
LName = UCase(Left(Thold, 1)) & right(Thold, Len(THold) - 1)
FName = FrName & " " & LName

'*********************************************************************
' Grab the password and set it to all lowercase
'*********************************************************************

PWord = LCase(arrInput(3))


Set adsUser = adsDomain.Create("user","cn=" & UName)
adsUser.Put "sAMAccountName", UName
adsUser.Put "userPrincipalName", UName & DomainAddr

'**********************************************************************
'Write the newly created object out from the property cache
'Read all the properties for the object, including
'the ones set by the system on creation
'**********************************************************************
adsUser.SetInfo
adsUser.GetInfo

'**********************************************************************
'Set the properties
'**********************************************************************
adsUser.AccountDisabled = False
adsUser.IsAccountLocked = False
adsUser.LoginScript = "login.bat"
if CreateProfilePath Then
adsUser.Profile = ServerName & ProfilePath & UName
End if
adsUser.PasswordRequired = True
adsUser.DisplayName = Fname
adsUser.FullName = Fname
adsUser.Description = FName
adsUser.Firstname = FrName
adsuser.Lastname = LName

'**********************************************************************
'Set the Home Directory
'**********************************************************************
adsUser.Put "homeDrive", "H:"
adsUser.HomeDirectory = ServerName & "\" & UName & "$"

'**********************************************************************
'Set the password
'**********************************************************************
adsUser.SetPassword PWord
adsUser.pwdLastSet = 0


'**********************************************************************
'Stop referencing this user
'**********************************************************************

adsUser.SetInfo
Set adsUser = Nothing

'**********************************************************************
'Create the home directory
'**********************************************************************

If Not fso.FolderExists(DataDrive & HomePath & UName) Then
Set fldUserHomedir = fso.CreateFolder(DataDrive & HomePath & UName)
End If


'**********************************************************************
'Set full rights for the user to the Home directory and Share it Out
'**********************************************************************
ShareRem = " /GRANT:Everyone,Full /UNLIMITED /REMARK:""" & FName
Set wshShell = WScript.CreateObject("Wscript.Shell")
wshShell.Run "cacls " & DataDrive & HomePath & UName & " /e /g " &
UName & ":C", 1, True
wshShell.Run "net share " & UName & "$=" & DataDrive & HomePath & UName
& ShareRem, 1, True
Wend

**********************THESE ARE THE LINES I HAVE ADDED AND ARE THE
ITEMS IN QUESTION********


'***********************************************************************************************
'Add new user to the Students Group
'***********************************************************************************************

Set objGroup =
GetObject("LDAP://CN=StudentsMSE,OU=GroupsMSE,OU=Groups,dc=fhs_svr";)
ObjGroup.add "LDAP://CN="; & UName & ",CN=Users,DC=fhs_svr"
ObjGroup.SetInfo

'*********************************
'Close the file
'*********************************

tsInputFile.Close

.



Relevant Pages

  • RE: export user accounts from NT 4.0 domain
    ... ATTENTION THE SCRIPT MUST BE RUNNED FROM A COMPUTER WHERE EXCEL IS ... from the information in a Microsoft Excel spreadsheet. ... Dim strLast, strFirst, strMiddle, strPW, intRow, intCol ... On Error GoTo 0 ...
    (microsoft.public.windows.server.scripting)
  • Re: Password Expire
    ... We have one fron end Edge server in our DMZ which passes email onto two ... I used to schedule a script to run every 24 hours on my Exchange 2003 ... Dim fso, txtarray, BodyText ... Call ProcessFolder (objContainer, numDays) ...
    (microsoft.public.exchange.admin)
  • Re: LDAP query information
    ... a "Dim" statement. ... execution of the script. ... ' Filter on computer object. ... ' Construct LDAP syntax query. ...
    (microsoft.public.windows.server.scripting)
  • Re: ADSI Problem
    ... Right I've got the script working now with my ASP applications by passing the ... If you are doing forms authentication using ADSI (which it sounds like you ... Restarting IIS usually gets it working again. ... Dim strUserName ...
    (microsoft.public.windows.server.active_directory)
  • Re: Script: Remote shutdown of all domain computers
    ... When trying to run the script from a XP workstation, where i am logged in as ... Dim strBase, strFilter, strAttributes, strQuery, objRecordSet ... 2000 or above and allow shutdown, ... Public Function AllComputersAs String() ...
    (microsoft.public.windows.server.scripting)