User profile migration from one File Server to another.

Hi All, 

Sorry if this has already been answered but my search brings up nothing.  I am moving roaming user profiles from network location A, to network location B.  

My procedure is 

1. Run powershell script I wrote to take ownership of the profile files, give me full access to the profile files, fix profile permissions to reflect proper user permissions, move them to the new location, update active directory to reflect the new path.

2. Then I update the group policy for those users particular OU and their roaming profile location.

The issue is, even after I've moved the files and the profiles look to the new location, the user profiles still act as if they are being setup for the first time upon next login.

Basically is there a recommended way to move a users roaming profile, without it recreating the account?

Here is the code for the powershell script ( sorry for it not being documented ) just in case you want to look at it.  As far as I can tell though it successfully restores the correct ownership and permissions so I don't think the focus should be at the scripts code( as ugly as it may be )

A

Add-PSSnapin Quest.ActiveRoles.ADManagement -erroraction silentlycontinue
## RUN THIS SCRIPT AS ADMINISTRATOR 
###############
$loop="Y"
$PSSession = New-PSSession -ComputerName "CONTOSOFS01" -Credential "contoso\Administrator" 
while ($loop -eq "Y")
{
$Root=read-host "Enter the Customer OU"
$Groups="contoso\Administrator","contoso\sg.glo.GO Support Users","contoso\sg.loc.GO IT","ADMINISTRATOR","SYSTEM","contoso\svc.CreateAvGOUser","contoso\Nathan.Julsrud"
$PathsBeforeMigration="C:\IT\$Root.txt"
#####################

$users=get-qaduser -searchroot "OU=$Root,OU=customer GO,DC=contoso,DC=local" -sizelimit 0 | sort-object
get-date | out-file $PathsBeforeMigration -append
foreach ($user in $users)
{
$Username="contoso\"+$user.samaccountname
$samaccountname=$user.samaccountname
write-host -fore green "Processing $Username"
$Folders=@()
[string]$ProfilePath=$user.ProfilePath
$ProfilePath="$ProfilePath.V2"
[string]$HomeFolder=$user.HomeDirectory
$HomeFolder=$HomeFolder.Replace("\My Documents","")
"sAMAccountName=$Username" | out-file $PathsBeforeMigration -append
"ProfilePath=$ProfilePath" | out-file $PathsBeforeMigration -append
"HomeFolder=$HomeFolder" | out-file $PathsBeforeMigration -append
$ProfilePath=$ProfilePath.Replace("\\contoso.local\redirectedfolders","c:")
$HomeFolder=$HomeFolder.Replace("\\contoso.local\redirectedfolders","c:")
$Folders=$Folders + $ProfilePath
$Folders=$Folders + $HomeFolder
$Count=0
foreach ($Folder in $Folders)
{

$string=$String + '`n'
$Count++
if (Test-Path $Folder.Replace("c:","\\contosofs01\c$"))
{
write-host -fore cyan "Setting permissions on $Folder"
Invoke-Command -Session $PSSession -ScriptBlock { takeown /f $args[0] /r /d y} -argumentlist $Folder | out-null

foreach ($Group in $Groups)
{
Invoke-Command -Session $PSSession -ScriptBlock  { icacls $args[0] /grant "$($args[1]):(OI)(CI)F" /t  } -argumentlist ($Folder,$Group) | out-null 
}
Invoke-Command -Session $PSSession -ScriptBlock  { icacls $args[0] /grant "$($args[1]):(OI)(CI)F" /t  } -argumentlist ($Folder,$Username) | out-null 
Invoke-Command -Session $PSSession -ScriptBlock { icacls $args[0] /setowner $args[1] /c /t } -argumentlist ($Folder,$Username) | out-null 
write-host -fore cyan "Copying $Folder"

if ($Count -eq 1)
{
ROBOCOPY $Folder.Replace("c:","\\contosofs01\c$") "\\contosofs06\D$\Profiles\$samaccountname.V2" /E /R:0 /MIR /COPYALL | out-null
rename-Item $Folder.Replace("c:","\\contosos01\c$") "$Root.$samaccountname.V2"
}
else
{
ROBOCOPY $Folder.Replace("c:","\\contosofs01\c$") "\\contosofs06\D$\Home\$samaccountname" /E /R:0 /MIR /COPYALL | out-null
rename-Item $Folder.Replace("c:","\\contosofs01\c$") "$Root.$samaccountname"
}
}
else
{
"NotFound: $Folder" | out-file $PathsBeforeMigration -append
}
}
$NewP="\\contoso.local\RedirectedFolders\UserProfiles\$samaccountname"
"NewProfilePath=$NewP" | out-file $PathsBeforeMigration -append
$NewU="\\contoso.local\RedirectedFolders\HomeFolders\$samaccountname"
"NewHomeFolder=$NewU\My Documents" | out-file $PathsBeforeMigration -append
$user | set-qaduser -ProfilePath $NewP -HomeDirectory "$NewU\My Documents" | out-null
}
$loop=read-host "Run again? Y/*"
}

Remove-PSSession -Session $PSSession
write-host -fore green "Complete"
September 6th, 2013 5:54pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics