Problem with Addusers Script
- From: "Jason" <fn_ludwig@xxxxxxxxxx>
- Date: 23 Nov 2005 08:57:07 -0800
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
.
- Follow-Ups:
- Re: Problem with Addusers Script
- From: James Whitlow
- Re: Problem with Addusers Script
- Prev by Date: uploading and processing a password protected word document with asp
- Next by Date: Re: How do I get an output file after running ftp in vbs?
- Previous by thread: uploading and processing a password protected word document with asp
- Next by thread: Re: Problem with Addusers Script
- Index(es):
Relevant Pages
|