Last active
January 5, 2017 01:23
-
-
Save wandersick/b3e1a3a5d29901fd9e124d284af84306 to your computer and use it in GitHub Desktop.
Batch-Update Paths of Roaming Profile and Home Directory (for AD Migration)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Title: Batch-Update Paths of Roaming Profile and Home Directory (AD Migration) | |
# Version: 2.0 | |
# Date: 4 Jan 2017 | |
# Type: PowerShell | |
# Reference: https://blogs.technet.microsoft.com/heyscriptingguy/2013/08/14/use-powershell-to-change-sign-in-script-and-profile-path/ | |
# Usage: The script is separated in two sections. They should be copied and pasted individually as needed. | |
# To use in different scenarios, change $original and $desiredChange to the other servers' hostnames. Also, change ou=... dc=... to other names. | |
# To apply, copy and paste the script block in the Apply section; to restore; copy and paste the script block in the Restore section | |
# ------------------------------------------ | |
# Apply | |
$original = "\\\\oldServer\\subDir" | |
$desiredChange = "\\newServer\subDir" | |
Import-Module ActiveDirectory | |
$ou = "ou=Dept,dc=wandersick,dc=.local" | |
$properties = "ProfilePath","HomeDirectory" | |
Get-ADUser -Filter * -SearchBase $ou -Properties $properties | ForEach-Object { $ProfilePath = "{0}" -f $_.ProfilePath ; $ProfilePath = $ProfilePath -replace $original,$desiredChange ; Set-ADUser $_.samaccountname -ProfilePath $ProfilePath } | |
Get-ADUser -Filter * -SearchBase $ou -Properties $properties | ForEach-Object { $HomeDirectory = "{0}" -f $_.HomeDirectory ; $HomeDirectory = $HomeDirectory -replace $original,$desiredChange ; Set-ADUser $_.samaccountname -HomeDirectory $HomeDirectory } | |
# ------------------------------------------ | |
# Restore (Fallback) | |
$desiredChange = "\\newServer\subDir" | |
$original = "\\\\oldServer\\subDir" | |
Import-Module ActiveDirectory | |
$ou = "ou=Dept,dc=wandersick,dc=.local" | |
$properties = "ProfilePath","HomeDirectory" | |
Get-ADUser -Filter * -SearchBase $ou -Properties $properties | ForEach-Object { $ProfilePath = "{0}" -f $_.ProfilePath ; $ProfilePath = $ProfilePath -replace $desiredChange,$original ; Set-ADUser $_.samaccountname -ProfilePath $ProfilePath } | |
Get-ADUser -Filter * -SearchBase $ou -Properties $properties | ForEach-Object { $HomeDirectory = "{0}" -f $_.HomeDirectory ; $HomeDirectory = $HomeDirectory -replace $desiredChange,$original ; Set-ADUser $_.samaccountname -HomeDirectory $HomeDirectory } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment