PoshCode Archive  Artifact [606ea20fd7]

Artifact 606ea20fd74a9b9a5ca6c38bbc5b8f6723f15bc17c050f5319cfb438fc717247:

  • File Migrate-UsersSettings.ps1 — part of check-in [3d9f9f72a7] at 2018-06-10 13:44:11 on branch trunk — Migrates users settings roaming profiles and home directories to another server. (user: themoblin size: 1440)

# 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"
		}
}