Changing User Directory path

  • Thread starter Thread starter rebloomfield
  • Start date Start date
R

rebloomfield

Hi,

I have 1200 users that have their user directory set to
\\server1\username.

I need to change this to point to \\server2\username.

This also applies to the profile location.
Is this easily scriptable?

Cheers
 
Check KB320043.

Here's an exerpt:

Assign a Home Directory to a User from the Command Line
You can use the net user command to assign a home
directory to a user from the command line. For example, at
the command line, type net user
tester /homedir:\\server\tester$ , and then press ENTER to
assign the tester$ hidden shared folder on the server that
is named "server" to the user Tester.

Hope that helps.
 
This should get you most of the way there. It doesn't include the profile
path, but that should be just an extra line or two below the HomeDirectory.
Watch for line wraps and change the value for strHomeDir to your real server
name.

'==============start=============================
Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set objRoot = Getobject("LDAP://rootDSE")
strDomain = objRoot.Get("defaultNamingContext")

strHomeDir = "\\server2\"

Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADSDSOObject"
adoConnection.Open "", "", ""


strStartOU = InputBox ("Enter the OU where the user accounts reside:")


thisDate = FormatDateTime(Now(), 1)
fileName = userID & "HomeDir.txt"
set fileSys = CreateObject("Scripting.FileSystemObject")
set fileTxt = fileSys.OpenTextFile(fileName, ForAppending, True)
fileTxt.WriteLine(thisDate)
fileTxt.WriteLine(vbCrLF)

'On Error Resume Next
Set adoRecordset = adoConnection.Execute _
("<LDAP://" & strStartOU & "," & strDomain & ">;(objectCategory=person);" _
& "Name,SAMAccountName,ADsPath;SubTree")

adoRecordset.MoveFirst
While NOT adoRecordset.EOF
userADSPath = adoRecordset.Fields.Item("ADsPath")
strUserID = adoRecordset.Fields.Item("SAMAccountName")
set objUser = GetObject(userADSPath)
objUser.HomeDirectory = strHomeDir & strUserID
objUser.HomeDrive = "H:"
objUser.SetInfo

fileTxt.WriteLine("Home Directory and Drive set for " & strUserID)
adoRecordset.MoveNext

Wend

wscript.echo "End of script"
'========================end================================
 
Back
Top