# encoding: ascii
# api: powershell
# title: Migrate-UsersSettings
# description: Migrates users settings roaming profiles and home directories to another server.
# version: 0.1
# type: module
# author: themoblin
# license: CC0
# x-poshcode-id: 4651
# x-archived: 2014-02-09T11:33:53
# x-published: 2014-11-26T16:16:00
#
# Use my Copy Shares script (http://poshcode.org/4630) to copy the data and create the new shares first.
#
Import-Module Activedirectory
#Lower Case!!
$oldserver = "hostname"
#Lower Case!!
$newserver = "hostname"
$users = get-aduser -filter * -properties homedirectory,profilepath
foreach ($user in $users) {
$name = $user.name
$DN = $user.distinguishedname
$profilepath = $user.profilepath
$homedirectory = $user.homedirectory
if ($profilepath -like "*$oldserver*")
{
#Add -whatif to next line before running the script to see what would happen
Set-Aduser $DN -profilepath $profilepath.ToLower().replace($oldserver,$newserver)
}
else {
Write-Host -foregroundcolor RED "User $name does not have roaming profile on $oldserver"
}
if ($homedirectory -like "*$oldserver*")
{
#Add -whatif to next line before running the script to see what would happen
Set-Aduser $DN -homedirectory $homedirectory.ToLower().replace($oldserver,$newserver)
}
else {
Write-Host -foregroundcolor RED "User $name does not have a Home directory on $oldserver"
}
}