Link to home
Start Free TrialLog in
Avatar of DannyJohnEvans
DannyJohnEvans

asked on

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.
Avatar of arnold
arnold
Flag of United States of America image

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?
Avatar of DannyJohnEvans
DannyJohnEvans

ASKER

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.
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
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.
...
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.
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.
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.
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.
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>"
    }
}
ASKER CERTIFIED SOLUTION
Avatar of DannyJohnEvans
DannyJohnEvans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I believe the comments I posted helped you.
It provided a better fit to my needs.