Using PowerShell to move TsProfilePath for multiple users in AD
I am currently working on a file server migration project, part of the task is to move users TsProfilePath from \\ServerA\Profiles\%username% to \\ServerB\Profiles\%username%
Microsoft recommends to use GPO to Change a user's Terminal Services profile path
I payed with that a little bit. While find the GPO setting is easy but I have trouble to test it out. As some article mention that I need to put Citrix servers in a OU and then set GPO for that OU and it is a kind complicated and I don’t have the test environment to test it.
I then remember that we live in PowerShell age – after some trials and errors – here is the solution
Again I need to use Quest AD extension mentioned in yesterday’s blog
Here is old way
$users = Get-QADUser -SearchRoot 'xyz.com/TestOU'
foreach ($u in $users)
{$u.TsProfilePath = '\\ServerB\profiles\' + $u.sAMAccountName; $u.CommitChanges()}
Here is new way
Get-QADUser -SearchRoot 'xyz.com/TestOU'|%{$_.TsProfilePath ='\\ServerB\profiles\' + $_.sAMAccountName;$_.CommitChanges();}
Basically it does the same thing and the new “way” is a one liner which is neat. I finally passed that foreach hurdle!
No matter you use GPO or PowerShell, you still need to copy users TS profile from ServerA to Server B. Here we just change the pointer in user’s AD property
I want to warn you that Playing this in a production environment is very dangerous and it will easily mess things up!
That’s why I use -searchRoot to target a small test OU and even that I didn’t use $u.CommitChanges() until I am absolutely sure what’s going to happen.
Finally if you are the “brave” guy and ready to do this for your entire domain – DON’T DO THIS LIGHTLY!!!
Get-QADUser -sizelimit 0|%{$_.TsProfilePath ='\\ServerB\profiles\' + $_.sAMAccountName;$_.CommitChanges();}