Solved

Batch File Question

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

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now