PoshCode Archive  Artifact [61a97cba59]

Artifact 61a97cba59bc321deb4a126ec9c5ee012d21a4202aaf9693111cabcb376000ef:

  • File Update-User-Profiles.ps1 — part of check-in [c232be3e83] at 2018-06-10 13:54:11 on branch trunk — There was a script written by TheMoblin http://poshcode.org/4651 that started a discussion at the Powershell forums http://powershell.org/wp/forums/topic/how-to-make-this-more-useful-for-my-situation/ as I was having issues getting it to work in my particular situation. Mike Robbins responded with the below code. My original description for this was incorrect and this is an updated description to ensure Mike gets the correct credit as it is well deserved. (user: xspader size: 1424)

# encoding: ascii
# api: powershell
# title: Update User Profiles
# description: There was a script written by TheMoblin http://poshcode.org/4651 that started a discussion at the Powershell forums http://powershell.org/wp/forums/topic/how-to-make-this-more-useful-for-my-situation/ as I was having issues getting it to work in my particular situation. Mike Robbins responded with the below code. My original description for this was incorrect and this is an updated description to ensure Mike gets the correct credit as it is well deserved.
# version: 0.1
# type: module
# author: xspader
# license: CC0
# x-poshcode-id: 5370
# x-archived: 2015-06-23T00:29:13
# x-published: 2015-08-15T00:08:00
#
# I added n the SearchBase section to better fit my situation.
#
$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)
    }
}