I have created the below script to aid IT staff with USMT migrations. The aim is of it is to list the available migration stores categorised by date and then select them using a series of user input menu's.
The problem is however that is if the user inputs the correct value, there are no issues, if a wrong value is entered then the script continues and contains incorrect values in the directory structure variables. I have tried to use if not exist but my code just caused the script into an infinite loop. If anyone can help me with a way to mitigate these errors I'd appreciate it I'm an infrastructure guy not a programmer ;)
:LOADSTATEW732 cls dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%" Set /P loadstateday=Please enter day(01-31): cls dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%" Set /P loadstatemonth=Please enter month(01-12): cls dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%\%loadstatemonth%" Set /P loadstateyear=Please enter year(Example 2011): cls ECHO You have selected: Day: %loadstateday% Month: %loadstatemonth% Year: %loadstateyear% ECHO. Set /P loadstateset=Are these settings correct? (Enter Yes/No): IF %loadstateset% == Yes GOTO LOADSTATEGO IF %loadstateset% == Y GOTO LOADSTATEGO IF %loadstateset% == NO GOTO LOADSTATEW732 IF %loadstateset% == N GOTO LOADSTATEW732 :LOADSTATEGO ECHO Exporting Migration Settings... "%CD%\loadstate.exe" \\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\% Loadstateday%\%Loadstatemonth%\%Loadstateyear% /c /i:userfiles.xml /i:migapp.xml /v:12 ECHO. pause GOTO MENU: Entire Script
@ECHO OFF :START :MIGSERVER cls ECHO. ECHO ____________________________________________________________ ECHO Please set the deployment server ECHO For example: UKHQITS017 FRPRAPS002 HUHKAPS001 etc ECHO. ECHO By default this script is configured to use the reminst ECHO share for USMT migrations. ECHO ____________________________________________________________ ECHO. Set /P MigServer=Please enter USMT Server: cls ECHO Server set to: %migserver% ECHO Please insure this is correct before continuing pause cls GOTO MENU: :MENU ECHO. ECHO ________________________________________________ ECHO User State Migration Tool v0.1 ECHO ________________________________________________ ECHO. ECHO 1 Check Directory parameters ECHO 2 Set USMT Server ECHO 3 Delete Unused User Profiles (XP ONLY) ECHO 4 Export migration settings from host system (Windows XP 32Bit) ECHO 5 Export migration settigns to target system (Windows 7 32Bit) ECHO 6 Exit ECHO. SET /P userChoice=Choose Option(1-6): IF %userchoice% == 1 GOTO DIRPARAMS IF %userchoice% == 2 GOTO MIGSERVER IF %userchoice% == 3 GOTO PROFDEL IF %userchoice% == 4 GOTO SCANSTATEXP32 IF %userchoice% == 5 GOTO LOADSTATEW732 IF %userchoice% == 6 GOTO QUITMENU :DIRPARAMS cls ECHO. ECHO Current USMT x86 Folder: %CD% ECHO Current USMT Migration Store Server: %migserver% ECHO. ECHO Please make sure of the following ECHO before continuing. ECHO. ECHO 1. You have set the correct migration server in the batch file. ECHO 2. The above directorys exist ECHO 3. The appropriate files are included within them ECHO. pause cls GOTO MENU: :PROFDEL cls ECHO User Profile Deletion - Please select which profiles you wish to remove. "%CD%\delprof2.exe" -c:127.0.0.1 -p -d:90 ECHO. pause GOTO MENU: :SCANSTATEXP32 cls ECHO Creating migration store....... "%CD%\scanstate.exe" "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%date%" /o /c /i:userfiles.xml /i:migapp.xml /v:12 ECHO. pause GOTO MENU: :LOADSTATEW732 cls dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%" Set /P loadstateday=Please enter day(01-31): cls dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%" Set /P loadstatemonth=Please enter month(01-12): cls dir "\\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%loadstateday%\%loadstatemonth%" Set /P loadstateyear=Please enter year(Example 2011): cls ECHO You have selected: Day: %loadstateday% Month: %loadstatemonth% Year: %loadstateyear% ECHO. Set /P loadstateset=Are these settings correct? (Enter Yes/No): IF %loadstateset% == Yes GOTO LOADSTATEGO IF %loadstateset% == Y GOTO LOADSTATEGO IF %loadstateset% == NO GOTO LOADSTATEW732 IF %loadstateset% == N GOTO LOADSTATEW732 :LOADSTATEGO ECHO Exporting Migration Settings... "%CD%\loadstate.exe" \\%migserver%\reminst\USMT XP to Windows 7\32Bit\%username%\%Loadstateday%\%Loadstatemonth%\%Loadstateyear% /c /i:userfiles.xml /i:migapp.xml /v:12 ECHO. pause GOTO MENU: :QUITMENU ECHO USM TOOL v0.1 has ended. pause