adding a user with script

D

Dave

I have created a script that adds users and an manually creates a home
folder and sets the permissions but It doesnt work until I go to the
users property and
choose apply. What do I have to do to get this to work without
choosing apply

Script below.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Script to create users in the Active Directory
'
' This script reads user names and attributes from the file called
users.txt
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Const WAIT_ON_RETURN = True
Const HIDE_WINDOW = 0


wscript.echo "Script starting. Please click OK to continue."

DIM arrRecord
Const ForReading = 1 ''''''''''''10

''''''''''''''''''''''''''''''''''''''''''''''''
' Determine the LDAP path for your domain
' Nothing in this section needs to be customized
''''''''''''''''''''''''''''''''''''''''''''''''
Set Root = GetObject("LDAP://RootDSE")
DomainPath = Root.Get("DefaultNamingContext")

''''''''''''''''''''''''''''''''''''''''''''''''
' Get the pointer to your domain object 20
' Nothing in this section needs to be customized
''''''''''''''''''''''''''''''''''''''''''''''''
Set Domain = GetObject("LDAP://" & DomainPath)

'*******************************************************************
'*******************************************************************
'*******************************************************************

'30
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Read records from file

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
set fso = CreateObject ("Scripting.FileSystemObject") ' The file
system object is your entry point into the file system

Set tsTextFile = fso.OpenTextFile ("ADDusers.txt", ForReading, False)
' Get the object to the ADDusers.txt text file

strRecord = tsTextFile.ReadLine
arrRecord = Split (strRecord, ",") ' SKIP FIRST LINE
strRecord = tsTextFile.ReadLine
arrRecord = Split (strRecord, ",") ' SKIP Second LINE

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Begin reading the input file and loop until you reach EOF 40
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

While Not tsTextFile.AtEndOfStream ' START OF LOOP

strRecord = tsTextFile.ReadLine
arrRecord = Split (strRecord, ",")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'text fields defined
'account,first,last,middle,discription,
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set objou = GetObject("LDAP://ou="& arrRecord(1) & ",ou=Students,ou="
& arrRecord(0) & ",ou=HS,"& DomainPath)
Set adsUser = objou.Create("User", "CN=" & arrRecord(3))
adsUser.Put "sAMAccountName", arrRecord(3) 'Account Name
adsUser.Put "givenName", arrRecord(4) 'First Name
adsUser.Put "sn", arrRecord(5) 'Last Name
adsUser.Put "initials", arrRecord(6) 'Middle Initial
adsUser.Put "userPrincipalName", arrRecord(3) '
adsUser.DisplayName = arrRecord(4) & " " & arrRecord(6) &". "&
arrRecord(5) 'Display Name
adsUser.SetInfo

''''''''''''''''''''''''''''''''''''''''''''''''''''''
adsUser.Description = arrRecord(4) & " " & arrRecord(6) &". "&
arrRecord(5)&" - " & arrRecord(2)&" "& arrRecord(1) 'Display Name
adsUser.SetPassword arrRecord(3)
adsUser.Put "pwdLastSet", CLng(0)

''''''''''''''''''''''''''''''''''''''''''''''''''''''
'adsUser.Put "profilePath", arrRecord(9) & "\"& arrRecord(1) & "\"&
arrRecord(2)& "\"& arrRecord(3)
adsUser.Put "scriptPath", arrRecord(8)
adsUser.Put "homeDirectory", arrRecord(9) & "\"& arrRecord(1) & "\"&
arrRecord(2)& "\"& arrRecord(3)
adsUser.Put "homeDrive", "P:"
adsUser.SetInfo

''''''''''''''''''''''''''''''''''''''''''''''''''''''
adsUser.AccountDisabled = False
' adsUser.HomeDirectory = arrRecord(9) & "\"& arrRecord(1) & "\"&
arrRecord(2)& "\"& arrRecord(3)
adsUser.SetInfo

'''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Reset adsUser in preparation for the next user object
' Nothing in this section needs to be customized
'''''''''''''''''''''''''''''''''''''''''''''''''''''''

Set adsUser = Nothing

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Calls sub that creates home folder
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
strSharePath= arrRecord(9) & "\" & arrRecord(1) & "\" & arrRecord(2) &
"\"

Call CreateHomeFolder(strSharePath,arrRecord(3))

Wend ' END OF LOOP


''''''''''''''''''''''''''''''''''''''''''''''''
' Close the text file
' Nothing in this section needs to be customized
''''''''''''''''''''''''''''''''''''''''''''''''

tsTextFile.Close


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Finished dialog box
' Nothing in this section needs to be customized
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
wscript.echo "Finished"



Sub CreateHomeFolder(strShare,strNumber)
Dim WshShell, strPath, arrCmd(1),strgrp, i

Set WshShell = Wscript.CreateObject("Wscript.Shell")

strPath = strShare & strNumber
arrCmd(0) = "cmd /c md " & strPath
' arrCmd(1) = "cacls " & strPath & " /e /g Administrators:F"
' arrCmd(0) = "cacls " & strPath & " /e /g NetworkAdmins:F"
arrCmd(1) = "cacls " & strPath & " /e /g " & strNumber& ":F"
' arrCmd(2) = "cacls " & strPath & " /e /r Users"

For i = LBound(arrCmd) To UBound(arrCmd)
Call WshShell.Run(arrCmd(i), HIDE_WINDOW, WAIT_ON_RETURN)
Next
End Sub
 
T

Tim Springston \(MSFT\)

Hi Dave-

This may not be the best forum to get assistance with debugging your script,
though some of the MVPs may be able to assist.

The alternatives would be to either use ADDUSERS.EXE from the Resource Kit,
where you provide an answer file for new user creation, or to post to the
Microsoft.public.windows.server.scripting newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top