PoshCode Archive  Artifact [6b6b9674c3]

Artifact 6b6b9674c33d4ee3730e6caec4cb2725cd9158e7eefe7c9270afddfd6af78c3c:

  • File Update-User-Profiles.ps1 — part of check-in [b0c7a7eaa0] at 2018-06-10 13:54:07 on branch trunk — 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. (user: xspader size: 1394)

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