Link to home
Start Free TrialLog in
Avatar of JHMH IT Staff
JHMH IT StaffFlag for United States of America

asked on

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.
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

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 dataUser generated image 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
Avatar of JHMH IT Staff

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Will Szymkowski
Will Szymkowski
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!
Yes you can export the current settings within excel and then modify them to match what i have illustrated in my CSV example.

Will.
%username% is their samaccount name and not their 'Display Name"
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.

Will.
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.
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)
{
$User.samaccountname
$User.NewPath
Set-ADUser -Identity $User.samaccountname -ProfilePath $User.NewPath
}

Open in new window