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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a home directory for each user

Status
Not open for further replies.

lintow

Programmer
Nov 29, 2004
82
0
0
US
Is there a way to set each users home directory when running this script

Const ForReading = 1
Set objShell = WScript.CreateObject ("WScript.Shell")
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Set fileObject = objFSO.OpenTextFile("C:\VB\File.txt", ForReading)

Do While Not fileObject.AtEndOfStream
strLine = fileObject.ReadLine

aArray = Split(strLine, ",")

sUser = aArray(0)
sPassword = aArray(1)
sEmail = aArray(2)

WScript.Echo sUser
WScript.Echo sPassword
WScript.Echo sEmail
'Loop

Dim oContainer
Dim oUser
Set oContainer=GetObject("LDAP://OU=Student,DC=MYCSU,DC=ces,DC=edu")
'Create user
Set oUser = oContainer.Create("User","CN=" & sUser)
'Assign values to user attributes
oUser.Put "samAccountName", sUser
oUser.SetPassword sPassword
oUser.Put "givenName", sUser
oUser.Put "sn", sUser
oUser.Put "userPrincipalName", sEmail
oUser.Put "mail", sEmail
oUser.SetInfo
oUser.SetPassword sPassword
oUser.SetInfo
oUser.AccountDisabled = False
oUser.SetInfo
'Clean up
Set oUser = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
'WScript.Quit
Loop
 
Code:
oUser.Put "homeDirectory","\\serverpath\" + oUser.SamAccountName & "$"
     	oUser.Put "homeDrive", "u:"
       	oUser.Setinfo

I hope you find this post helpful.

Regards,

Mark
 
This is what I setup, it works. I go to the LDAP and look into the profile and I see the directory there.

sample \\server1\Home\%wlinton%...this looks great

But the folder is not created in the home directory. If I change the name of the file %wlinton% to wlinton% ...and hit apply it creates the folder, but when I run the code, for some reason it does not create the folder but it sets the home directory. I tried to log off and log on as that user to see if it would create the folder, but it did not.

any suggestions

oUser.Put "homeDrive", "Z:"
oUser.Put "homeDirectory", "\\server1\Home\%" & sUser & "%"
oUser.SetInfo
 
dont you want

%username% rather than %literal_username%
 
Hmm you might want to try first setting the home directory value and using set info, then use the home drive setting and set info again.

I hope you find this post helpful.

Regards,

Mark
 
Ok I did this but it does not create the folder. I tried loggin off and then log back on to see if it would create the folder but it DOES NOT.

Is there some way to apply the settings for the folder
I can go to the LDAP and retype the folder name and then apply it, then it creates the folder. But I do not want to do this. I have over 500 users


oUser.Put "homeDrive", "Z:"
oUser.SetInfo
oUser.Put "homeDirectory", "\\server1\Home\%" & sUser & "%"
oUser.SetInfo
 
You can use the FileSystemObject to create the folder and should be able to script using XCACLs to set the permissions.

I hope you find this post helpful.

Regards,

Mark
 
Can you show me how this is done. Do you have a sample?

Also will this still show the map drive correctly when the user logs on.

I have seen some samples but I' not sure when the folders are created with the right permissions. Would the map drive show up correct when they log on?

any help would be appreciated
 
Here is the code to add to your existing script at the end.

Note that the three WSHShell lines should each be a single line. Window size in posting may have wrapped them.

Code:
Dim oFSO, WSHSHell, sFolder, sXpath

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = CreateObject("Wscript.Shell")

sFolder = "\\server1\Home\" & sUser"
'Change to where you have xcacls
sXpath =  "\\server1\utils\xcacls.exe"

If Not oFSO.FolderExists(sFolder) Then
	oFSO.CreateFolder(sFolder)
	WSHSHell.Run "cmd /C " & sXpath & " "& sFolder & " " & " /E /G Administrators:F"
	WSHSHell.Run "cmd /C " & sXpath & " "& sFolder & " " & " /E /G domainname\" & sUser & ":F" 
	WSHSHell.Run "cmd /C " & sXpath & " "& sFolder & " " & " /E /G System:F"
End If

I hope you find this post helpful.

Regards,

Mark
 
for some reason its not setting the permissions when I run the code. it create the folder but not the permissions

sFolder = "\\wider\Home\" & sUser
'Change to where you have xcacls
sXpath = "\\wider\Resource Kit\xcacls.exe"

If Not fs.FolderExists(sFolder) Then
fs.CreateFolder(sFolder)

ws.Run "cmd /C " & sXpath & " "& sFolder & " " & " /E /G Administrators:F"
ws.Run "cmd /C " & sXpath & " "& sFolder & " " & " /E /G ces.edu\" & sUser & ":F"
ws.Run "cmd /C " & sXpath & " "& sFolder & " " & " /E /G System:F"

 
What happens if you manually try to execute the same commands?

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top