Batch Script: Windows AD Migration


I worked on a Windows domain migration project several months ago. The P company acquired the B company, and request to migrate all former B company’s employees’ desktops and laptops to P company’s AD domain.

Firstly, I created all new AD accounts for B company’s employees in P company’s AD. Then I wrote the following batch script  and send it to the B company’s users, and tell them to run it at their convenience.

***********************************************************************

@echo off

REM ***choose XP or 7***
:START
SET /P OS_type=Please choose your OS: 1 for winXP, 2 for win7, q for quit:
IF “%OS_type%”==”q” GoTo EOF
IF “%OS_type%”==”1” echo You chosed winxp! & copy “c:\Domain_Migration\xp\netdom.exe” “c:\windows\system32\” /y & GoTo NEXT
IF “%OS_type%”==”2” (echo You chosed win7! & copy “c:\Domain_Migration\win7\netdom.exe” “c:\windows\system32\” /y & copy “c:\Domain_Migration\win7\netdom.exe.mui” “C:\Windows\System32\en-US\” /y & GoTo NEXT) ELSE (echo ERROR & GoTo START)

:NEXT
copy “c:\Domain_Migration\xcopy.exe” “c:\windows\system32\” /y
REM ***build the MoveProfile.bat***
cd c:\Domain_Migration\
echo cd %%USERPROFILE%% > MoveProfile.bat
echo xcopy “%USERPROFILE%\*” . /e /i /y >> MoveProfile.bat

REM ***build default username & domain***
echo Windows Registry Editor Version 5.00 > DefaultDomain.reg
echo [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon] >> DefaultDomain.reg
echo “DefaultDomainName”=”[NEW_DOMAIN_NAME]” >> DefaultDomain.reg
echo “DefaultUserName”=”%USERNAME%” >> DefaultDomain.reg

REM ***import the reg file ***
reg import DefaultDomain.reg

SET /a counter=0

:FALSE
REM ***join [NEW_DOMAIN_NAME] domain***
echo ——————————————————————————-
SET /a counter=%counter%+1
IF %Counter% GTR 3 (echo You have typed the wrong password 3 times, to avoid to be locked please try it again later. & pause & goto EOF) ELSE (echo ATTENTION: You are using the new domain account! & netdom move %COMPUTERNAME% /Domain:[NEW_DOMAIN_NAME] /UserD:[NEW_DOMAIN_NAME]\%USERNAME% /PasswordD:*)

IF %ERRORLEVEL%==0 GoTo TRUE
IF NOT %ERRORLEVEL%==0 GoTo FALSE

:TRUE
REM ***add [NEW_DOMAIN_NAME] user to local admin***
net localgroup administrators [NEW_DOMAIN_NAME]\%USERNAME% /add
echo Rebooting….
IF “%OS_type%”==”1” shutdown -r -f -t 10
IF “%OS_type%”==”2” shutdown /r /f /t 10

:EOF
exit

***********************************************************************

You also can click here to download my whole migration package including the windows utilities and the script.

How to use the package?

1) Unzip the ‘Domain_Migration’ folder to C:\ drive.

2) Double click the ‘ClickMe.bat’ then follow the instruction displayed in the DOS window.

3) If you want to keep your profile, double click ‘MoveProfile.bat’ after the reboot.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s