Change profile and home folder path with a script

What I want to do:
Change the profile path and the home folder path for a specific OU with a vbs script.

Here is a script I`ve found that maybe can be used:

Set objOU = GetObject _

objUser.Put "profilePath", "\\sea-dc-01\Profiles\myerken"
objUser.Put "scriptPath", "logon.bat"
objUser.Put "homeDirectory", "\\sea-dc-01\HomeFolders\myerken"
objUser.Put "homeDrive", "H"


When I run this script from a domain controller I get this error error:
Line: 1
Char: 1
Error: A referral was returned from the server
Code: 8007202B
Source: (null)

Anyone that knows what is wrong?

Eventually got a better/easier script for the task I want to perform?
Who is Participating?
You're adding the username with "&" -- using %username% is redundant.  If you change the following two lines I think you'll accomplish what you're looking for:

obj.profilePath = "\\sea-dc-01\" &
obj.homeDirectory = "\\sea-dc-01\" & & "-profile"

This will make the user's profile folder match the user's common-Name attribute; their homeDirectory will be their common-Name, a dash and then the word profile.  For example, assume the person's name is John Doe, their common-Name is Doe John, then their directories would be:
  Home Directory :  \\sea-dc-01\Doe John
  Profile              :  \\sea-dc-01\Doe John-profile

If this isn't the format you wanted please post they way you would like the directory names to appear.  
Check the spelling of your LDAP objects.  Look for clues particularly the Line: number.  In this case it Char: 1 is not to blame.  When none of the line can execute, the error gets charged to the first character. In the case of runtime errors if you are desperate then use this work around.  Add this line: On Error Resume Next

jeringAuthor Commented:
I made it work using this:

Set ou = Getobject("LDAP://OU=test,ou=BTOTEST,ou=Skoler,dc=elev,dc=steinkjer,dc=local")

For each obj in ou

obj.profilePath = "\\sea-dc-01\%username%" &
obj.scriptPath = "logon.vbs"
obj.homeDirectory = "\\sea-dc-01\%username%-profile" &
obj.homeDrive = "H:"


MsgBox "OU update complete"

It works fine, except that I get this path:
\\sea-dc-01\%username%profil test

So the %username% works, but it adds its code before the username. Any suggestions how to solve this?
jeringAuthor Commented:
Thank you VERY much! Now it worked excactly the way I wanted!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.