Mass Change Roaming Profile Path in Active Directory

I have a fun one today: we are splitting our primary file server into two servers to make snapshots possible (virtual servers backed up by Veeam). We use roaming profiles and folder redirection for all users, which are the files moving from the current server - which we'll call SERVER1 - to the new SERVER2.

How can I mass change the roaming profile path in AD from "\\SERVER1\Profiles\{user}" to "\\SERVER2\Profiles\{user}" without using the %USERNAME% environment variable? The issue is that not all current folder assignments match the username, so using the variable will cause close to 20% of our users to lose their existing profile. I essentially need to loop through all users and replace "SERVER1" with "SERVER2" without modifying the rest of the string.
JHMH IT StaffAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
If dealing with large amounts of data
what you can do is robocopy /e /copyall /zb /r:3 /w:5 /xo the files from server1old to server2new, wait until all users are logged off (weekend) and change the group policy to point to server2new
Small Amounts of datahave this checked if not checked, let all users logoff and logon, then remove the policy the files will move back to the users computers, then apply the policy with the new share location This time use the %username%  Why you didn't before baffles my mind
JHMH IT StaffAuthor Commented:
The redirects won't be a problem, it's the profile path under each user's account setting. If everything were so simple as to be set up correctly from the start we wouldn't need Experts Exchange lol...the current naming convention was adopted to be able to quickly identify user folders when corrective action needs to be taken. However older users were set up with accounts which utilized the first 3 letters of their last name and last 4 digits of their SSN, so using the %USERNAME% variable will cause John Smith (for example) to lose his Outlook and other configurations since his profile folder will change from jsmith to smi1234.

Not the end of the world, but in this environment the more painless I can make this for the end users the better.
Will SzymkowskiSenior Solution ArchitectCommented:
Yes you can do this using powershell however you will need the entire path of where the user profile will be. below is a script that will do this. You need to construct your CSV with the following Headings / data below...

samaccountname     NewPath
msmith                       \\server2\profiles\msmith
barbhope                   \\server2\profiles\barbh
mdavis                        \\server2\profiles\mdavis
$DriveLetter = "N:"
$Profiles = Import-csv "c:\yourcsvname.csv"
ForEach ($User in $Profiles) {
Set-ADUser -Identity $User.samaccountname -HomeDirectory $User.NewPath -HomeDrive $DriveLetter

Open in new window

Thats it. Just make sure that you have your CSV file constructed like i have illustrated above.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JHMH IT StaffAuthor Commented:
If I can query the AD for the current paths I can strip the strings to get only the current folder name to use to construct the CSV. I'll try tomorrow!
Will SzymkowskiSenior Solution ArchitectCommented:
Yes you can export the current settings within excel and then modify them to match what i have illustrated in my CSV example.

David Johnson, CD, MVPOwnerCommented:
%username% is their samaccount name and not their 'Display Name"
Will SzymkowskiSenior Solution ArchitectCommented:
We know that David. We need to call the current users by their samaccountname first when using Set-Aduser -identity, then you modify the value of the account with the entire path as I have illustrated in the CSV example.

The script I have provided will work for the askers requirements.

JHMH IT StaffAuthor Commented:
Yes, what I'm going to attempt is to query the AD to export a CSV with the current profile path, find and replace all instances of SERVER1 with SERVER2, then upload the modified CSV with the provided PowerShell script.

I have some test accounts I can try it on, will update today once I have results.
JHMH IT StaffAuthor Commented:
Perhaps include "Import -Module ActiveDirectory" in the future for us noobs LOL

Otherwise EUREKA! This will save a significant amount of complaining from users who otherwise may have lost their Outlook profile and other personalization settings! Final code:
Import-Module ActiveDirectory
$Profiles = Import-csv "C:\AD-Profile-test1.csv"
ForEach ($User in $Profiles)
Set-ADUser -Identity $User.samaccountname -ProfilePath $User.NewPath

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.