Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent...Could you please help me with this script

Status
Not open for further replies.

209912

MIS
Jan 7, 2004
7
CA
HI,

I'm working in an environnemnt where new users are constantly create in batch. I had previously run a script to create the userss home folders and set the appropriate permission for these users. Now with new users being created all the time, i woul like to have a script that will scan all my users, check to see if their homedrive fiel is empty, if yes, then the script will update the user homedrive settings, create the user folder on a specifics file servers, grant the appropriates permissions. In revanche i wont like to touch the old user settings
i have these scripts that i initially run the fisrt time. My problem is that i dont know how to combine these scripts to get them run without touching the my old users,but just update my new users settings.

Thanks


--Script 1

Query the OU members and create the users home directory

Set objOU = GetObject("LDAP://ou=users,ou=test,dc=test,dc=test,dc=ca")
ObjOU.Filter= Array("user")
For each objUser in ObjOU
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("\\server\Users\"&objUser.SAMAccountName)

Next


--Script 2

Query the user to set the homedirectory path and the drive letter associated

Set objOU = GetObject("LDAP://ou=users,ou=test,dc=test,dc=test,dc=ca")
ObjOU.Filter= Array("user")
For each objUser in ObjOU
if Objuser.homeDrive = ""
Then
objUser.Put "homeDirectory", "\\server\users\"&objUser.SAMAccountName
objUser.Put "homeDrive", "P:"
objUser.SetInfo
--Script 3

Query the system file to set the appropriate permission

home = "\\server\Users"
Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(home)
Set fc = f.Subfolders
For Each f1 in fc
Set objOU = GetObject("LDAP://ou=users,ou=test,dc=test,dc=test,dc=ca")
For each objUser in ObjOU
userHome = objUser.SAMAccountName
admin = "administrators"
system = "system"
username = Mid ( Ltrim(objUser.Name), 4, Len( objUser.Name ) )
userName2 = username & "@test.ca"
If Left(userName2,1) <> &quot;_&quot; and userName <> &quot;Xrenee.lesage&quot; Then
cmd = &quot;cmd /c echo y| cacls &quot; & home & &quot;\&quot; & userHome & &quot; /c /g &quot; & userName2 & &quot;:f &quot; & system & &quot;:f &quot; & admin &&quot;:f&quot;
ret = ws.Run(cmd,0,true)

End If
Next
Next


Next

 
This might seem like a dumb question, but why don't you do all of this as one process when you create the new users?

If your existing users are not to be touched why not use a script to create new users in batch and as part of that process create the user directory and populate the home directory field?

Another thought for you would be to eliminate the home directory and simply map the drive in a login script.

Just seems to me like you are making more work for yourself. Am I missing the point here?
 
Thanks for your response,

I have to go througth this process because the user creation is handle by another script running on the Human ressource control that i dont have. I'm working in a university enviroment where students get registered and created all the time and mostly by term. Also i cannot have a logon script as each department administrator is in charge for creating their own logon script. As a central service provider i have to allocate a space for the student when they get registered from HR and created in AD. My plan is to have this script and run it regulary as a routine job.

Thanks
 
I get that there are some political issue, but can't you modify the HR script to do what you need at the same time they do their part? You could ask their admin to place a call to your script and feed it an argument. That way they really don't have to modify their code except to add to call your stuff at the end.

If that doesn't seem like an option I'll see what I can do for a script to do as you asked.
 
HI,

The HR script is controled by another team that does not have access to our environnement directly for political reason, the only thing that this script is allowed to do is to create the users as they get registered in the oracle database in HR. Everything regarding users settings latter is in our side. While i was sending these mail i come to a script that i have tested and it seems to work, in revanche i would like to be able to log the action the script is doing like write username and tell if the user profile has been updated yes or no. Maybe you could help me to accomplish this.

Thanks Again, Here is the script

'-------------------------------------------------------------------------
'User homeDrive Script delta users home directory creation
'
'
'Ran
'-------------------------------------------------------------------------

Dim objOU
Dim objUser
Dim ws
Dim fs
Dim f
Dim fc
Dim objFolder
Dim home



'Query the user to set the homedirectory path and the drive letter associated

Set objOU = GetObject(&quot;LDAP://ou=test,dc=test,dc=test,dc=ca&quot;)
ObjOU.Filter= Array(&quot;user&quot;)
For each objUser in ObjOU
If objUser.homeDirectory = &quot;&quot; Then
objUser.Put &quot;homeDirectory&quot;, &quot;\\server\users\&quot;&objUser.SAMAccountName
objUser.Put &quot;homeDrive&quot;, &quot;P:&quot;
objUser.SetInfo
home = &quot;\\server\Users&quot;
Set ws = WScript.CreateObject(&quot;WScript.Shell&quot;)
Set fs = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set objFolder = fs.CreateFolder(&quot;\\server\Users\&quot;&objUser.SAMAccountName)
Set f = fs.GetFolder(home)
userHome = objUser.SAMAccountName
admin = &quot;administrators&quot;
system = &quot;system&quot;
username = Mid ( Ltrim(objUser.Name), 4, Len( objUser.Name ) )
userName2 = username & &quot;@test.ca&quot;
If Left(userName2,1) <> &quot;_&quot; and userName <> &quot;Xrenee.lesage&quot; Then
cmd = &quot;cmd /c echo y| cacls &quot; & home & &quot;\&quot; & userHome & &quot; /c /g &quot; & userName2 & &quot;:f &quot; &
system & &quot;:f &quot; & admin &&quot;:f&quot;
ret = ws.Run(cmd,0,true)
End If

End If
Next
 
Since the Create User script does not set the user home directory, why not scan AD for users with no Home directory. Set it for those users only.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top