Link to home
Start Free TrialLog in
Avatar of Cuteadder
CuteadderFlag for Australia

asked on

VB script to transfer user files between domains

We are about to kick off a big project moving about 200 users between domains, the users will be moved onto a new domain, with a new format of username and a new computer.

I want to use a VB script to move, Desktop & Favorites & My Documents from within Documents and Settings.

Ideally, one vb script on the old computer to be run when logged onto a admin, that will prompt for the username, then move the three above folders to a network share, then prompt when finished.

Then the user logs onto the new computer and off, so that a admin can log on and...

Then another vb script to prompt for the old username and the new username, and then move the three folders back onto the NEW computer and prompt when complete...

I have a little bit of code before, but am not a code guru... please help!
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
 
 
RootSource = "D:\Audio\"
RootDestination = "\\some computer name\audio\"
 
strfolder = InputBox("Please Input folder name:", "Your vbs")
 
If not objFSO.FolderExists(RootDestination & strfolder) Then
 
	objFSO.CreateFolder(RootDestination & strfolder)
End IF 
 
strcmd = "xcopy """ & RootSource & strfolder & "\*.*"" """ & RootDestination & strfolder & """ /S /Y /E "
'Wscript.Echo strcmd
 
strCommand = WshShell.Run(strcmd, 0, True) 
 
Wscript.Echo strCommand 
 
Set objFSO = nothing
Set WshShell = nothing

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MaxSoullard
MaxSoullard
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Are you looking to just move regular user Files between machines?  That's all that will happen if you copy those folders.  Nothing user-related in the registry will be moved at all such as application settings , Windows preferences, etc.  That might not be a bad thing to start from scratch though!

If you are wanting to move actual user profiles, Microsoft has a nice tool called User State Migration Tool (USMT) that will do this and you can even migrate profiles between operating system versions if the users are going from XP to Vista or 7 on their new computers.

If they are going from XP to Vista or 7 and you just want to use MaxSoullard's script, the User Profile folder path is also going to be different on the different operating systems.  I use this little bit of code if my scripts need direct access to non-specific User Profile folders.  Replace lines 17 and 68 in MaxSoullard's code above with this attached code:

It will grab the "AllUsersProfile" variable from the local machine and remove the "All Users" part at the end then add the User name from the Input box.

Set objWSHShell = WScript.CreateObject("WScript.Shell")
strProfileFolder = Replace(objWSHShell.ExpandEnvironmentStrings("%AllUsersProfile%"),"All Users","") & strUserName

Open in new window

Avatar of Cuteadder

ASKER

Yeah I've usmt before, but my personal preference is a clean copy of just the files that the user needs, plus with the users going onto a different domain etc.

Thank you for all your help.