We help IT Professionals succeed at work.

Script to change all users home directory of a site

As I am upgrading our File server to a new server, and number of users for that particular site is more then 200. As we should change all users home directory of this site which is a big headache doing it manually and possibility of mistake as well for that want to do it through command prompt or any vbscript. Does any buddy know a VBscript or command that first get all users of this site then change their home Directory.

Thanks
Comment
Watch Question

Mike ThomasConsultant
Top Expert 2010
Commented:
You can do it in bulk in AD by selecting all users in an OU (CTRL+A) then right clicking and selecting properties, you will be presented with what options you can change for all users in one go, all you need do is change the path to

\\servername\sharename\%username%

the variable %username% will auto change to the actual username.

Author

Commented:

Yes it a good option but the problem is that users are in different OUs and some of them are not having Home drive as well. For that i am looking through script.
 
Mike ThomasConsultant
Top Expert 2010

Commented:
Try this thread for an idea.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21315790.html

I use a tool called AD find and replace from dovestone software for such things but that costs money.
Premkumar YogeswaranSr. Analyst - System Administrator

Commented:
Site in the sense

Do you want to change the Homke Directory path based on Office Location?
Premkumar YogeswaranSr. Analyst - System Administrator
Commented:
If it is based on location, Check this query below

This query will pull the user in chennai location and only the active user not the disabled user

dsquery * -filter "(&(&(&(&(|(&(objectCategory=person)(objectSid=*)(!samAccountType:1.2.840.113556.1.4.804:=3))(&(objectCategory=person)(!objectSid=*))(&(objectCategory=group)(groupType:1.2.840.113556.1.4.804:=14))))(objectCategory=user)(physicalDeliveryOfficeName=Chennai*))) (&(&(objectClass=user)(objectCategory=person))(!UserAccountControl:1.2.840.113556.1.4.803:=2)))" -limit 0 | dsmod user -hmdir \\servername\share -hmdir h:

Let me know if you have any issue

Cheers,
Prem
dsquery * -filter "(&(&(&(&(|(&(objectCategory=person)(objectSid=*)(!samAccountType:1.2.840.113556.1.4.804:=3))(&(objectCategory=person)(!objectSid=*))(&(objectCategory=group)(groupType:1.2.840.113556.1.4.804:=14))))(objectCategory=user)(physicalDeliveryOfficeName=Chennai*))) (&(&(objectClass=user)(objectCategory=person))(!UserAccountControl:1.2.840.113556.1.4.803:=2)))" -limit 0 | dsmod user -hmdir \\servername\share -hmdir h:

Open in new window

Author

Commented:

Prem! Do u mean by office location  site name in AD, As sites are called physical structure of Ad where we define subnets, location name along with replications for communication.
Premkumar YogeswaranSr. Analyst - System Administrator

Commented:
HI,

You cannot query the computer based on Site...!

There should be some common attribute for that user objects.

Based on that we can query and modify the User account in AD.

Regards,
Prem
You may be able to do this with the quest active directory powerhsell scripts. From your question it looks like you are trying to query the homedirectory attribute in AD. If that is the case this is the syntax you can use

get-qaduser -homedirectory {current dir} | set-qaduser -homedirectory {new dir}

The tools can be DL here
http://www.quest.com/powershell/activeroles-server.aspx
Also another way of doing this using DSquery would be this

Dsquery * -filter "(&(objectCategory=user)(homeDrive=Value))" | dsmod user -hmdrv {path}
Commented:
Tnx Every one, The safiest way i find first i qury in Active directory users and computer and then change the path by selecting all users.