0

I want to change the serial number and product number of about 250 servers (they are not correct at the moment). I know the command that I need to use, but I need to be able to input certain options in to that command and then run it.

The options I need are:

  1. A prompt for selecting the update of the serial or the product number
  2. Multiple prompts for actual serial number, an IP address, a user name and password on having selected before the update of the serial number
  3. Multiple prompts for actual product number, an IP address, a user name and password on having selected before the update of the product number

The command I wish to run via the batch file is:

asu64 set SYSTEM_PROD_DATA.SysInfoSerialNum XXXXXXX --host XXX.XXX.XXX.XXX --user XXXX --password XXXX

The XXX is a user defined input. I'd also like for completion and then go back to the initial selection menu.

Here is what I have done so far. (Please excuse the simplicity of it. I am very new to this stuff.)

@ECHO OFF
ECHO Test Code
ECHO.
ECHO 1.Serial Number
ECHO 2.Product Name
ECHO.
CHOICE /C 12 /M "Enter your choice:"
ECHO.
IF CHOICE 1 GOTO SerialNumber
IF CHOICE 2 GOTO ProductName

:SerialNumber
ECHO Serial Number 
GOTO End

:ProductNumber
ECHO Product Number
GOTO End

PAUSE

Many thanks for any help you can offer.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
AshSalhan
  • 3
  • 1

1 Answers1

0

There could be used for this task:

@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "IpAddress="
set "NameUser="
set "Password="

:MainMenu
cls
echo(
echo   1 ... Serial number
echo   2 ... Product number
echo   E ... Exit
echo(
%SystemRoot%\System32\choice.exe /C 12E /N /M "Enter your choice:"
if errorlevel 3 exit /B
if not errorlevel 1 goto MainMenu
echo(
if errorlevel 2 goto ProductNumber

set "NumberText=serial"
set "NumberOption=SYSTEM_PROD_DATA.SysInfoSerialNum"
goto NumberPrompt

:ProductNumber
set "NumberText=product"
set "NumberOption=SYSTEM_PROD_DATA.SysInfoProductNum"

:NumberPrompt
set "NumberValue="
set /P "NumberValue=Please enter %NumberText% number: " || goto NumberPrompt
set "NumberValue=%NumberValue:"=%"
if not defined NumberValue goto NumberPrompt

echo(
if defined IpAddress (set "Default= [%IpAddress%]") else set "Default="
:IpPrompt
set /P "IpAddress=Please enter IP address%Default%: "
if not defined IpAddress goto IpPrompt
set "IpAddress=%IpAddress:"=%"
if not defined IpAddress goto IpPrompt

echo(
if defined NameUser (set "Default= [%NameUser%]") else set "Default="
:NamePrompt
set /P "NameUser=Please enter user name%Default%: "
if not defined NameUser goto NamePrompt
set "NameUser=%NameUser:"=%"
if not defined NameUser goto NamePrompt

echo(
if defined Password (set "Default= [%Password%]") else set "Default="
:PasswordPrompt
set /P "Password=Please enter password%Default%: "
if not defined Password goto PasswordPrompt
set "Password=%Password:"=%"
if not defined Password goto PasswordPrompt

echo(
"%~dp0ASU64.exe" set %NumberOption% "%NumberValue%" --host "%IpAddress%" --user "%NameUser%" --password "%Password%"
echo(
if not errorlevel 1 (
       echo The update of the %NumberText% number "%NumberValue%" was successful.
) else echo ERROR: The update of the %NumberText% number "%NumberValue%" failed!
echo(
%SystemRoot%\System32\choice.exe /C CE /N /T 10 /D C /M "Press C to continue or E to exit ..."
if not errorlevel 2 goto MainMenu
endlocal

The executable ASU64.exe is referenced with full path of the batch file which means the executable must be always in the same directory as the batch file. The current directory of cmd.exe processing the batch file does not matter in this case.

Please read the following answers for the explanation of the code:

To understand the commands used and how they work, open a command prompt window, execute there the following commands, and read the displayed help pages for each command, entirely and carefully.

  • call /? ... explains %~dp0 ... drive and path of argument 0 which is the batch file path.
  • choice /?
  • echo /?
  • endlocal /?
  • exit /?
  • goto /?
  • if /?
  • set /?
  • setlocal /?
Mofi
  • 46,139
  • 17
  • 80
  • 143