?
Solved

Batch File Question

Posted on 2014-04-23
2
Medium Priority
?
538 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 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