# encoding: ascii
# api: powershell
# title: Update User Profiles
# description: This is an update to the original script from TheMoblin http://poshcode.org/4651 for larger implementations for larger AD infrastructure. I had help with this from Don and Mike at Powershell.org forums.
# version: 0.1
# type: module
# author: xspader
# license: CC0
# x-poshcode-id: 5367
# x-derived-from-id: 5368
# x-archived: 2015-06-19T01:37:15
# x-published: 2015-08-13T23:39:00
#
# This allows for only the users that need to be updated to be actioned, and also allows for targetting to a specific OU. This was updated to cope with a rather flat OU structure with thousands of user objects in each OU when only a few hundred may need updating
#
$OldServer = 'OldServer'
$NewServer = 'NewServer'
Import-Module ActiveDirectory
Get-ADUser -Filter "Enabled -eq 'true' -and HomeDirectory -like '*$OldServer*' -or ProfilePath -like '*$OldServer*'" -SearchBase "OU=xx,DC=xx,DC=xx,DC=xx" -Properties HomeDirectory, ProfilePath |
ForEach-Object {
if ($_.HomeDirectory -like "*$OldServer*") {
Set-ADUser -Identity $_.DistinguishedName -HomeDirectory $($_.HomeDirectory -replace $OldServer, $NewServer)
}
if ($_.ProfilePath -like "*$OldServer*") {
Set-ADUser -Identity $_.DistinguishedName -ProfilePath $($_.ProfilePath -replace $OldServer, $NewServer)
}
}