Solved

Batch File Question

Posted on 2014-04-23
2
537 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 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 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