Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Batch File Question

Posted on 2014-04-23
2
Medium Priority
?
539 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

610 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