User and Data Migration – Script to move files

I’m wondering if somebody can assist with the migration of user data from one server to another.
We have created all the users within the destination domain, and have all the old users and folder structure in the source domain.
The problem is within the destination domain the users have a new username, so moving the current file structure is out of the question.
So my question is do you know of a way to move files and folders from on location over another based on username variables, so for example…

Source folder Name for a user called Joe Blogs is Joeb and the destination folder is now called Blogsj in the destination domain.

So is there a way to move all the files for around 1000 users?
Thank you in advance, any assistance is greatly appreciated.
DannyJohnEvansAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
You can use a CSV file as an input to a script that has old username/new username mapping.
The difficulty is that ntfs security parameters can not be copied if needed.
Is there a trust relationship between the old server and the new domain, dealing with credentials to access new server from old server.
Batch meaning you only use bat or vb/powershell are also a possibility?
0
DannyJohnEvansAuthor Commented:
Hi Arnold,

Many thanks for the quick response.
Yes I thought of doing that, do you have any example scripts and CSV files?
The domains are totally separated at the moment, permissions between the two domains shouldn't be to much of a problem as I can open up the SMB file share first and enter the cross domain credentials.

Also the NTFS permissions have already been created on the destination domain.

Thank You.
0
GiladnCommented:
Hi,

when you say folders what do you mean? are you working with roaming profiles or mapped\redirected folders?

if you have a shared folder of all users data in source server you can just move them over to the destination server, use this utility (link below)  to rename the folders, afterwards you can set the profile (active directory) to map  the users profile(all users will have the same mapping) to  \\server\share\%username%   where %username% is the new username upon logon to the new server and \\server\share\%username% will point to the new share on the destination server( after you moved the files and renamed the folders) -  %username% should match.
 if I understand correctly the pattern will be the same for all users.

now you have to give permissions , full control to creator owner(the user) , administrators and system.
set a logon script on the new group policy that you will create and  will be linked to the users container in active directory.

here you will find a nice script that sets the folder+files permission according to the directory in runs at (scroll down at the link)

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/815ce790-529f-4223-804d-374bfcac91c3/script-to-automate-change-of-folder-permissions-and-ownership-based-on-the-name-of-the-folder?forum=ITCG


Bulk Rename Utility

http://www.howtogeek.com/howto/45646/bulk-rename-tool-is-a-lightweight-but-powerful-renaming-tool/

Hope I understood exactly what you want.. review carefully.

Waiting for  your reply,

Gilad
0
What were the top attacks of Q1 2018?

The Threat Lab team analyzes data from WatchGuard’s Firebox Feed, internal and partner threat intelligence, and a research honeynet, to provide insightful analysis about the top threats on the Internet. Check out our Q1 2018 report for smart, practical security advice today!

arnoldCommented:
A CSV is one you would need to create
Old username,new username
Joeb,Blogsj

depending which scripting you will use, you would likely preload the CSV as an array/hash where the old username is the index/reference whose value will be the new username

The issue with ntfs mentioned dealt with variations of setting where inherited permissions from parent are not set.  In the case you are dealing with these documents are within the user's profile or the four folders desktop, documents, appdata, start menu.

I.e. Robocopy using /copy:dats will not be useful OS joeb will not exist on the destination and copying joeb security settings from old to the new domain will not be useful.

Le me see if I can provide a powershell example dealing with the logic.

Outside the CSV, queries to the AD to identify the user may ... Add complexity or you may have to do a two step process.
On the old domain, export:
name, username
Using the new AD lookup username using the name in the query.
...
0
DannyJohnEvansAuthor Commented:
Hi,

As far as I can see the Bulk rename utility is not advanced enough to rename based on variables. It seems to work well if you are just wanting to add numbers, or a prefix & suffix. But if i wanted to rename and entire directory of folder names from the old account names to the new ones it wouldn't work. So to clarify...

We have two domains, for the purpose of this post I will call them domain1 and domain2. Within each domain we have a file server called fileserver1 and fileserver2

(Sample account name Joe Blogs)
domain 1 user accounts have userPrincipalName of Joeb@domain1.local

domain 2 user accounts have userPrincipalName of joeblogs@domain2.local
(So first 3 letters of the first name and then the last name)

There is a folder share on both files servers that gets mapped at logon. The folders represent the userPrincipalName so Joe Blogs folders look like...

Fileserver1 Joeb
Fileserver2 joeblogs

The problem I'm having is trying to migrate the data from fileserver1 to fileserver2 due to the change of usernames. I hope this makes better sense.

I really appreciate the responses so far.
Thank you.
0
arnoldCommented:
You can script the rename using powershell tie into AD. Of each domain.
List directory content on filserver1 extracting the username portion. Query domain1 DC for the user's Name. Then using the second connection to domain2 DC  using the name to identify the new username.
Using this info you can now copy the old to the new
Presumably your though is to map filserver2's root on filserver1 and copy to it.
0
DannyJohnEvansAuthor Commented:
Hi Arnold,

Thanks again for the response,  can you provide an example or a link to a powershell script as a starting point please?

I understand the principle, but need a little help.

Thank you.
0
arnoldCommented:
A powershell reference can be followed from the ms powershell page https://technet.microsoft.com/en-us/scriptcenter/dd742419

It has examples.  The question whether you want all to be done within powershell including copying the data or will you rely on robocopy or similar tool to handle the copying?

Unfortunately I do not have a ready made example on hand to post.
For reference:
First, list directories,
Using the data, extract the username,
Ad connection/query.
0
DannyJohnEvansAuthor Commented:
Can anybody else provide an example script please? I've been doing a lot of digging over the past few days but cannot find anything suitable. The only thing I've found is...

I'm uncertain how this would work on different domains.

function onDeprovision($Request)
{
    if ($Request.class -eq "user")
    {
      $sAMAccountName = $Request.Get("sAMAccountName")
      robocopy.exe "\\server1\profile$\$sAMAccountName" "\\server1\profile$\Moved" /R:0 /W:0 /E /XO /LOG:"<some path to a log file>"
    }
}
0
DannyJohnEvansAuthor Commented:
Hi All,
Just I quick update to say I’ve managed to solve this issue, and hopefully it may help somebody else…
First of all I exported the sAMAccountName and EmployeeID from both domains using the PowerShell script below:

import-module activedirectory
Get-ADUser -Filter * -Properties sAMAccountName, EmployeeID | select sAMAccountName, EmployeeID | Export-CSV "C:\Domain1.csv"

Once I had both of the files I then married the users up using the employee ID that didn’t change between both domains. This allow me to create a CSV file based on the format below, I used synkronizer  (http://www.synkronizer.com/) to merge the two files.

Source      Destination
Joeb            joeblogs
…              …

Once I had the excel file I then created the following PowerShell script the copy the files:
$csvFile = "Path the excel document we created earlier"
$srchome = "\\path to source
$dsthome = "\\path to destination
$logfile = "path to log file "

Import-Csv $csvFile |
    ForEach-Object {
        $srcDoc = '"{0}\{1}"' -f $srcHome,$_.Source
        $dstDoc = '"{0}\{1}"' -f $dstHome,$_.Destination
        Write-Host $srcDoc,$dsrDoc -ForegroundColor green
        RoboCopy $srcDoc $dstDoc /z /e /np /MIR  /r:10 /w:40 /log+:$logFile
    }

Thanks again for all the responses.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
arnoldCommented:
I believe the comments I posted helped you.
1
DannyJohnEvansAuthor Commented:
It provided a better fit to my needs.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.