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
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