Link to home
Start Free TrialLog in
Avatar of derekjr
derekjr

asked on

VBScript to move user's home folder to new file server

I am looking for a script to copy user's home folder and permissions from one file server to another.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia 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
SOLUTION
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
Avatar of derekjr
derekjr

ASKER

it is a homedirve migration. we don't have it set it active directory. it is in the login script with the use of  ifmember.
Avatar of derekjr

ASKER

C:\robocopy.exe G:\MetaDocs \\NT23\D$\MetaDocs /Z /R:5 /COPYALL /MIR /FP /LOG+:G:\MetaDocs\MetaDocs.log /TEE /XF MetaDocs.log
 
 I found this to use with robocopy. the thing is there is two folders under the metadocs folder that i want to exclude. What would i add in  to exclude t?hese two folders?
 Also the folder is already created on NT23 so how would i run it?
Use the /XD switch to exclude folders
for example:
/XD "path to folder"
Since you are running in mirroring mode it doesn't matter that the folder already exists.
Be sure to make a test run first!
Avatar of derekjr

ASKER

so just running that command will work without any modification?
you could remove /COPYALL since you are already the /MIR option but that shouldn't be harmfull. The rest of your command looks fine!
You can exclude multiple directories by adding the as following:
/XD "first path to exclude" "second path to exclude"
You can even use wildcards! For example /XD *temp*
I would strongly recommend using a test source and destination location before running it in production. But I think you are good to go!
 
Avatar of derekjr

ASKER

i tested and it didn't copy the permissions
 
Avatar of derekjr

ASKER

actually it copied the permissions inside of the folder but the root TEST folder share and permissions didn't copy. so this is what it was supposed to look  like.
 
D:\test    supposed to be shared out as test
d:\test\test  Not shared out but NTFS permissions have been applied
 
ok, adding /SEC would definitely add the security, but I believe /MIR should do it also. Try it without /COPYALL
Avatar of derekjr

ASKER

still didn't share out the root test folder
 
Avatar of derekjr

ASKER

with removing copyall it didn't apply the ntfs permissions either
 
Our previous comments crossed eachother, but this is probably an inheritance issue.
I have made the following test: I created c:\temp and c:\temp\test, then I added some files to c:\temp\test
I disabled inheritance on c:\temp and added some security settings to the c:\temp\test folder and some files
Then I ran:

robocopy /MIR c:\temp\test c:\temp\test2
Security of c:\temp\test and c:\temp\test2 and it's contents are identical
Avatar of derekjr

ASKER

did you share out the  folder also?
 
nope, robocopy will not copy share permissions or make a share of the destionation. it will only copy NTFS permissions.
If it's just one share you can share it manually and set the permissions. Or do you have a load of shares?
Hi, the VBS code below can be used to create a share on a server.

I guess after the move, you could iterate through all new user folders on the new server, and share each of them.

I wrote some code to share home directories here:
https://www.experts-exchange.com/questions/22693616/Need-VB-script-to-add-multiple-user-to-2000-domain-from-excel-spreadsheet.html

Regards,

Rob.
Sub ShareFolder(strServer, strFolderToShare, strShareName, strDescription)
	' http://msdn.microsoft.com/en-us/library/aa389393(VS.85).aspx
	Const FILE_SHARE = 0
	Const MAXIMUM_CONNECTIONS = 25
	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
	Set objNewShare = objWMIService.Get("Win32_Share")
	errReturn = objNewShare.Create(strFolderToShare, strShareName, FILE_SHARE, MAXIMUM_CONNECTIONS, strDescription)
End Sub

Open in new window

Avatar of derekjr

ASKER

It is only one share. so i shared it manually. i ran a test copy of the whole dir tonight and it showed this.
 

   Total    Copied   Skipped  Mismatch    FAILED    Extras
     Dirs :      7063      7059         4         0         0       387
    Files :     48938     48686        10         0       242      1588
    Bytes :  54.045 g  53.839 g    2.71 m         0  208.16 m   1.189 g
    Times :   1:20:39   1:16:05                       0:02:30   0:02:04
    Speed :            12662995 Bytes/sec.
    Speed :             724.582 MegaBytes/min.
    Ended : Wed Jan 07 18:01:51 2009
 
 
 How can i find what files failed?  i browsed through the log file and couldn't see anything
 
Hi, if you add the /V option to your RoboCopy command, you'll get verbose output, and should be able to which files failed.

Regards,

Rob.
Avatar of derekjr

ASKER

Actually inside everyones folder i have a copierscan share that i need to share it. Can i use the above script?
 

@ECHO OFF
REM This creates and sets permissions to all CopierScan folders
PUSHD G:\METADOCS
DIR /B >G:\METADOCS.TXT
FOR /F %%J IN (G:\METADOCS.TXT) DO MD G:\METADOCS\%%J\CopierScan
FOR /F %%J IN (G:\METADOCS.TXT) DO NET SHARE %%JCOPIERSCAN$=G:\METADOCS\%%J\COPIERSCAN /GRANT:%%J,FULL /GRANT:COPIERADMIN,FULL
FOR /F %%J IN (G:\METADOCS.TXT) DO XCACLS G:\METADOCS\%%J\CopierScan /Y /C /G "COPIERADMIN":F;F "%%J":F;F "Domain Admins":F;F
PAUSE
 
 I had this but it doesn't seem to be working
Try this. It should give you some output as it goes.

Regards,

Rob.
@ECHO OFF
REM This creates and sets permissions to all CopierScan folders 
PUSHD G:\METADOCS
DIR /B >G:\METADOCS.TXT 
FOR /F %%J IN (G:\METADOCS.TXT) DO(
If Not Exist G:\METADOCS\%%J\CopierScan MD G:\METADOCS\%%J\CopierScan
Echo Creating %%JCOPIERSCAN$ share on G:\METADOCS\%%J\COPIERSCAN
NET SHARE %%JCOPIERSCAN$=G:\METADOCS\%%J\COPIERSCAN /GRANT:%%J,FULL /GRANT:COPIERADMIN,FULL
XCACLS G:\METADOCS\%%J\CopierScan /Y /C /G "COPIERADMIN":F;F "%%J":F;F "Domain Admins":F;F)
PAUSE

Open in new window

Avatar of derekjr

ASKER

wow the something crazy happen. myself and my co worker already had our folders in the new share. we had our PST's that were left to copy. it copied them and  now that is the onky thing in the folder???
Well that's strange.

The only extra thing my version did was echo a line that tells you which folder it's acting on...as you can by the Echo line.

Plus I also added a check to see if CopierScan existed before creating it.

Perhaps you should create your own
G:\MetaDocs.txt
file that has only one or two subfolder names from G:\MetaDocs for testing.

Then comment out this line:
DIR /B >G:\METADOCS.TXT

and you will be able to control which subfolders it acts on, depending on what you put in G:\MetaDocs.txt

Regards,

Rob.
@ECHO OFF
REM This creates and sets permissions to all CopierScan folders 
PUSHD G:\METADOCS
DIR /B >G:\METADOCS.TXT 
FOR /F %%J IN (G:\METADOCS.TXT) DO If Not Exist G:\METADOCS\%%J\CopierScan MD G:\METADOCS\%%J\CopierScan
FOR /F %%J IN (G:\METADOCS.TXT) DO Echo Creating %%JCOPIERSCAN$ share on G:\METADOCS\%%J\COPIERSCAN
FOR /F %%J IN (G:\METADOCS.TXT) DO NET SHARE %%JCOPIERSCAN$=G:\METADOCS\%%J\COPIERSCAN /GRANT:%%J,FULL /GRANT:COPIERADMIN,FULL
FOR /F %%J IN (G:\METADOCS.TXT) DO XCACLS G:\METADOCS\%%J\CopierScan /Y /C /G "COPIERADMIN":F;F "%%J":F;F "Domain Admins":F;F
PAUSE

Open in new window

Avatar of derekjr

ASKER

ugh this makes no damn sense. why would it delete what was in the folder?
No idea.  There's nothing in that bacth file that does any deletion.....

But....maybe it was RoboCopy mirror that did it.  Which direction did you do the RoboCopy in?

The syntax is
RoboCopy <source> <destination> .....

so that would copy everything from <source> to <destination>

If you accidentally did it
RoboCopy <destination> <source> .....

with the /MIR option, then I dare say that might have done it....

Regards,

Rob.
Avatar of derekjr

ASKER

this is what i ran
 
C:\robocopy.exe G:\metadocs \\NT23\D$\metadocs /Z /R:5 /COPYALL  /MIR /FP /LOG+:G:\metadocs\metadocs.log /TEE /XF metadocs.log
 
source dest was right
 
So that would mean that G:\MetaDocs was the original location, and \\NT23\D$\MetaDocs was the new location to copy the stuff to?

If that's the case, you should not have lost anything....

Rob.
Avatar of derekjr

ASKER

So on nt23\metadocs under my folder i had all my documents. on the other server nt06\metadocs i had my PST's. Doing the copy wouldn't mirror nt06\metadocs which was just my pst's onto NT23\metadocs ??
 
We might tegmine_it to clarify this, but I'd say it was assumed by "home folder migration" that the destination location was emtpy, waiting for files to be migrated across.  The /MIR option of RoboCopy makes Destination the *same* as Source.

I believe (again, perhaps tegmine_it can clarify), if you wanted the folder "combined" you would have needed to leave out the /MIR option.

I'm sorry to hear that this has happened. It looks like you may need to restore what was lost from
\\nt23\d$\metadocs

and try again...perhaps testing on some test folders where you have data on both sides already.

Regards,

Rob.
If I understand correctly you first ran a robocopy, than placed the .PST files in the destination and then ran robocopy again?
This would result in loss of your .PST files. The /MIR option means that it's going to make an exact mirror of your source to the destination (except for excluded items with /XF , /XD).
If something different happened please let it know and we'll try to help.