Solved

Batch File Question

Posted on 2014-04-23
2
533 Views
Last Modified: 2014-04-23
I am working on a batch script to run the scanstate and loadstate part of the USMT tools. I have everything working the way I want but I want to prevent user error on a couple of parts so I will just include the sections in question.

On the script below, I want to be able to use the DIR command to check certain network share, give me a list of directories in that share and it then will ask the user to type the directory they want to use. It then gives a list of directories inside that directory and again it asks the user to specify which one they want to use.

What I want to do here is to be able to check the user input against the directories in the share and if there is a match use the GOTO command to move on to the next section but if there is no match I want to echo a message and then send the user back to the same section we were just working on.

At the moment this is not working like I would like to. My idea was to use the IF EXIST GOTO X and then IF NOT EXIST ECHO blahblah and GOTO Y

Anyone has any recommendations?
@ECHO OFF

:START

:LOADSTATE
cls
ECHO The following is a list of computers on the migration repository
ECHO Please select a computer from the list.
ECHO.
dir "\\SHARE\USMT\UserProfiles" /ad /O /P /W /B
ECHO.
Set /P MigComputer=Enter Computer Name of the computer you are migrating from:
ECHO Computer Name has been set to %MigComputer%

IF EXIST "\\SHARE\USMT\Userptofiles\%MigComputer%" (
GOTO MigUser
)

IF NOT EXIST "\\SHARE\USMT\Userptofiles\%MigComputer%" (
ECHO %MigComputer% does not exist. Please check your spelling.
)
IF NOT EXIST "\\HCDC\Public\USMT\Userptofiles\%MigComputer%" (
GOTO LOADSTATE
)

:MIGUSER
dir "\\SHARE\USMT\UserProfiles\%MigComputer%" /ad /O /P /W /B
Set /P Miguser=Enter profile name of the user you are migrating:
ECHO User has been set to %MigUser%
ECHO.
pause


Thanks
0
Comment
Question by:troubleshooter141
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 40018503
If you copied and pasted the script, then the main reason why it isn't working is that your test against "Userptofiles" instead of UserProfiles.
@echo off 
setlocal
:START

:LOADSTATE
cls
ECHO The following is a list of computers on the migration repository
ECHO Please select a computer from the list.
ECHO.
dir "\\SHARE\USMT\UserProfiles" /ad /O /P /W /B
ECHO.
Set /P MigComputer=Enter Computer Name of the computer you are migrating from:
ECHO Computer Name has been set to %MigComputer%
IF EXIST "\\SHARE\USMT\UserProfiles\%MigComputer%" (
	GOTO MigUser
)
ECHO %MigComputer% does not exist. Please check your spelling.
GOTO LOADSTATE

:MIGUSER
dir "\\SHARE\USMT\UserProfiles\%MigComputer%" /ad /O /P /W /B
Set /P Miguser=Enter profile name of the user you are migrating:
ECHO User has been set to %MigUser%
IF EXIST "\\SHARE\USMT\UserProfiles\%MigComputer%\%MigUser%" (
	GOTO CONTINUE
)
ECHO %MigUser% does not exist. Please check your spelling.
GOTO MIGUSER

:CONTINUE
ECHO Folders found, continuing with the migration.
ECHO.
pause

Open in new window

On a side note: if the user is supposed to be running this script on the very machine whose name he is supposed to pick from the first list, you have that information in the default variable "%ComputerName%".
And if the user is supposed to pick his own user name in the second list, you have that information in the default variable "%UserName%".
0
 
LVL 3

Author Closing Comment

by:troubleshooter141
ID: 40018529
Ok, I feel pretty stupid now.... after messing with it half a day you were right and it was just the spelling.

I did however add a pause after the echo message as it was flashing on the screen and going to the :LOADSTATE so the user never saw it which is what threw me off earlier.


Thanks for the second pair of eyes on this.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question