Avatar of teodor76
teodor76
 asked on

Change profile and home folder paths on the all the users in AD

I would like to change the profile path and the home folder path for all the users a specific OU with a vbs script..there are 600 users on AD.what is the better/easier script for the task I want to perform?
Active Directory

Avatar of undefined
Last Comment
teodor76

8/22/2022 - Mon
SOLUTION
Joseph Daly

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Chris Dent


If they're all in the same OU are you aware that you can do this in AD Users and Computer?

Select them all (in AD Users and Computers), then Open the Properties then explicitly change those two (and only those two) by ticking the box beside them and setting the new value.

Of course we can do this in VbScript if you're after it doing something a bit more complex.

Chris
Joseph Daly

In that example above the {startnode} is replaced by the distinguished name of the OU where the users are.
teodor76

ASKER
thank you for your information.
I have selected a few test users in AD and then click properties and I  typed a new user profile path and home
profile path= \\serverX\profile\%username%
home path=\\serverX\home\%username% because username is changing for every user..I gets error when I type "%username%"
Also 1 would like to try dsquery..links that you type is not working.could you please write dsquery as detailed? what will I write the username place  for every seperate user?
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Joseph Daly

I dont understand what this means
"Also 1 would like to try dsquery..links that you type is not working.could you please write dsquery as detailed? what will I write the username place  for every seperate user?"

I just tested the links and both of them are live.

The special token $username$ (case insensitive) may be used to place the
SAM account name in the value of -webpg, -profile, -hmdir, and
-email parameter.
For example, if the target user DN is
CN=Jane Doe,CN=users,CN=microsoft,CN=com and the SAM account name
attribute is "janed," the -hmdir parameter can have the following
substitution:

-hmdir \users\$username$\home

The value of the -hmdir parameter is modified to the following value:

- hmdir \users\janed\home



teodor76

ASKER
Set objOU = GetObject("LDAP://OU=somewhere,OU=somewhereelse,DC=yourdomain,DC=com")
 
 on tob,I have a one OU named XX,its further down,there are five OU structure named Xa,Xb,Xc,Xd,Xe..I would like to change only users' profile and home paths in the named Xd OU..how can I write ldap Query?
(LDAP://OU=XX,OU=Xd,DC=yourdomain,DC=com) or
(LDAP://OU=Xd,,DC=yourdomain,DC=com)

 

 

Chris Dent


That would change this line to:

Set objOU = GetObject("LDAP://OU=Xd,OU=XX,DC=yourdomain,DC=com")

It goes in reverse order, so domain.com/xx/xd in AD users and computers will become the above.

Chris
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
teodor76

ASKER
I get the following error when I run the .vbs file named profile.vbs by clicking on the domain controller
Set objOU = GetObject("LDAP://OU=Xd,OU=XX,DC=microsoft,DC=com")
 
objOU.Filter = Array("user")
For Each objUser in objOU
  objUser.Put "homeDirectory", "\\dc-srv-01\home$\" & objUser.Get("sAMAccountName")
  objUser.Put "profilePath", "\\dc-srv-01\profile$\" & objUser.Get("sAMAccountName")
  objUser.SetInfo
Next
the error> Line=2,Char=1, Error=A referral was returned from the server.Code=8007202B,Source=null
 
Joseph Daly

If you dont want to do it by command line you could probably also accomplish this fairly easily using admodify.,net.

http://technet.microsoft.com/en-us/library/aa996216(EXCHG.65).aspx

download here
http://admodify.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=6065
Chris Dent


That would suggest the path supplied is invalid (doesn't exist on the server you made the request to).

Trying to think of the easiest way to check the path...

If you have the Support Tools installed, open up ADSIEdit.msc (Start, Run). Then browse to the OU you want to make the changes to, open up the Properties and take a look at the "distinguishedName" attribute. The value there is the one we want to use in the script.

Chris
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
teodor76

ASKER
yes you are right..I made a mistake.I have adjusted the distinguishedName for OUs from ADSIEdit.msc
first, 1 tried Chris's vbscript and it didnt give me a error but nothing happened when 1 click on dc..no error,no message,no change
second,I tried xxdcmast's solution dsquery user "OU=Xd,OU=XX,DC=microsoft,DC=com" |dsmod user -profile \\ds-srv-01\profile$\$username$ -hmdrv \\dc-srv-01\home$\$username$
it works wihthout errors and it returned the following changes for each user on AD
profile=\\ds-srv01\profiles$\$username$  (it didnt give me  usernames in that OUservername=true,profiles$=true but no username)
home=it didnt changed. why didnt it change? also it doesnt available drive name=H
it will be in this way
home folder=
connect=drive letter  to=\\ds-srv01\profiles$\user's name