Back to Forums








View Full Version : Move users


snyde
March 9th, 2003, 19:42 PM
Hi just having a little play with batch files a home.

does anybody know if this would work , and write an error log at the same time.

I know its a bit long, is there any way to shorten it.

@echo off
rem 1 username i
rem 2 displayname j
rem 3 ?
rem 4 discription k
rem 5 old home drive l
rem 6 home path m
rem 7 profile n
rem 8 logon script o


if "%1" == "" goto help
if "%1" == "-?" goto help
if "%1" == "/?" goto help


echo Errorlog of movem2 created: > error.log
date /T >> error.log
time /T >> error.log
echo if there is nothing below here everything went OK >> error.log


cls
echo Reading In .csv %1 file
echo --------------------------------------------------------------------

for /F "skip=1 delims=, tokens=1,2,3,4,5,6,7,8" %%i IN (%1) do (

echo user: %%i

echo -
echo setting owner of \\fileserver\users\%%i and subdirectories to Administrator
subinacl /subdirectories \\fileserver\users\%%i\* /setowner=administrator
if ERRORLEVEL 1 (echo setting ownership on \\fileserver\users\%%i did not work: %ERRORLEVEL% >> error.log)

echo -
echo giving rights to Domain\administartor on \\fileserver\users\%%i
xcacls \\fileserver\users\%%i /T /E /G DOMAIN\administrator:F;F /y
if ERRORLEVEL 1 (echo setting admin permissions on \\fileserver\users\%%i did not work: %ERRORLEVEL% >> error.log)

echo -
echo moving \%%i to \\SERVER\users\%%i
xcopy s:\%%i e:\users\%%i /E /C /I /H /A /O
if ERRORLEVEL 1 (echo xcopy on %%i did not work %ERRORLEVEL%>> error.log)

echo -
echo setting owner of \\SERVER\users\%%i and subdirectories to %%i
subinacl /subdirectories \\SERVER\users\%%i\* /setowner=%%i
if ERRORLEVEL 1 (echo setting ownership on \\fileserver\users\%%i did not work: %ERRORLEVEL% >> error.log)

echo -
echo setting DOMAIN\administrator permissions on \\SERVER\users\%%i
xcacls e:\users\%%i /T /E /G DOMAIN\administrator:F;F /y
if ERRORLEVEL 1 (echo setting admin permissions on \\SERVER\users\%%i did not work: %ERRORLEVEL% >> error.log)

echo -
echo setting DOMAIN\administrator permissions on \\SERVER\users\%%i
xcacls e:\users\%%i /T /E /G DOMAIN\staff:R;R /y
if ERRORLEVEL 1 (echo setting staff permissions on \\SERVER\users\%%i did not work: %ERRORLEVEL% >> error.log)

echo -
echo setting DOMAIN permissions on \\SERVER\users\%%i
xcacls e:\users\%%i /T /E /G %%i:C;C /y
if ERRORLEVEL 1 (echo setting DOMAIN permissions on \\SERVER\users\%%i did not work: %ERRORLEVEL% >> error.log)

echo -
echo changing profile of %%i
cusrmgr -u %%i -U %%n -h \\SERVER\users\%%i -n %%o +s CanNotChangePassword
if ERRORLEVEL 1 (echo changing of profile on %%i did not work: %ERRORLEVEL% >> error.log)


echo ""
echo ----------------------------------
echo ""


)

echo ""
echo Synchronising DCs
echo --------------------------------------------------------------------
nltest /server:SERVER /pdc_repl

echo Finished, press any key to look at the error log
pause
type error.log

goto exit

:help
cls
echo --------------------------------------------------------------------
echo Script to Move Users and change their directories file permissions
echo Usage:
echo movem [filename] - where filename is a csv.
echo e.g. movem DOMAINusers.csv
echo --------------------------------------------------------------------

:exit


Cheers for looking.


:D :D

Dehcbad25
March 12th, 2003, 04:36 AM
I don't really want to test it at work, and I don't have much network at home, but I think it looks interesting:D
Exactly what is that you are trying to acomplish with this batch file?
I know it says to move users and file permisions, but could you give us a practical example???
Thanks;)

Big Booger
March 12th, 2003, 08:48 AM
atlas you are venturing into an area into which I haven't a clue. I will be watching this thread for a more informed source to give their opinion on the batch code for which you have written. Could be interesting.
:D

Welcome to TZ.

snyde
March 12th, 2003, 15:47 PM
Just trying to move users from an nt server to a new 2000 server.

But the home dirs were set with full control(before me) so the little bliters changed file perms and denied admins everything.
also needed to change profile path.

i think it works, but wasnt sure about the error log though.

cheers

Big Booger
March 12th, 2003, 22:19 PM
The following site might help in regards to creating an error log in a batch file.

http://www.computerhope.com/batch.htm

then again, it may not.
:D

Dehcbad25
March 13th, 2003, 00:50 AM
Alright, now I understand.
That is a very Interesting batch. Actually I am VERY interested in it, since I am planning to upgrade the servers to Windows 2K server, from the awfull NT server. I had already given up in anything automated :D, though all users in my Domain have different permisions.
Sorry I can test it now, but I would glady hear from the results :D