Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Scripts to change all the users home folder path pointing to the new file server.


Recommended Posts

Posted

I have migrated all of our users folders to a new server. From \\Server-A\StaffDocShare\UserName, To \\Server-B\StaffDocShare\Username

 

When I go to the Users properties in the Active directory - Profile- Home Folder

 

It Says Connect to “H” Drive To \\Server-A\ StaffDocShare \username

 

Is there an easy way to change all the Users home drives pointing to Server-B

\\File server-B\StaffDocShare\username

 

The name of the share is StaffDocShare

In the AD We have a main OU called: Staff

- Admin

-Teachers

 

In the Admin OU there are 50 users and in Teachers OU there are 150 users. Manually editing the home drive path for each user is time consuming.

Please suggest if there are ant tools or batch files to do this task.

 

Thanks any help would be great

Posted

Select all users in the OU, right click, select Properties, click on the Profile tab, select the home drive letter as H, type the new location in, but for the username part do %Username%.

 

%Username% will fill in the correct username for each account.

  • Thanks 2
Posted

This PowerShell script should do the trick. Change the bit in red to the relevant OU path.

 

Get-ADUser -SearchBase '[color="#FF0000"]OU=Staff,OU=Users,DC=example,DC=net[/color]' -Properties * -LDAPFilter "(&(homeDirectory=\\Server-A\StaffDocShare\*))" -SearchScope Subtree | ForEach-Object {

   $NewHome = "{0}\{1}" -f '\\Server-B\StaffDocShare', $_.sAMAccountName

   Set-ADUser -Identity $_ -HomeDirectory $NewHome -HomeDrive H: -WhatIf

}

 

Remove the -WhatIf parameter on Set-ADUser once you are happy it does what you need (unless you have already done it using @DJ-1701's method of course). :)

  • Thanks 1
Guest obsidianpillar
Posted
... also consider setting up DFS to make this process less "painful" next time... :)
Posted

To prevent needing to do this in the future setup DFS.

Overview of DFS Namespaces

You don't need to have it replicate or have multiple targets, this will just give a single unchanging unc path for your shares.

Then when you need to change the server they are hosted on, just change the target in DFS. The end users will never know the difference.

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...