Batch Script Code error

SERVERSEYE.txt
Kindly find the above attached code.
Hello,

I am trying to make a batch file that get system information of list of servers.
List of servers is listed in Servers.txt file
could you please advise why it's not working. kindly find the below code:
----------------------------------------
REM set variables
set manufacturer=
set model=
set serialnumber=
set name=
set ustring=
set pstring=

:USERNAME
REM Get Username
set user=%username%
set /p user=[Admin Username  / Press Enter For %username%] :

REM Check If Other Username
IF NOT %user% == %username% goto newuser
goto start

:NEWUSER
REM It's A Different User
set ustring=/user:"%user%"

:PASSWORD
REM Get Password
echo Password:
set pass=
set /p pass=

REM Check if password was entered
IF [%pass%] == [] goto nopass
set pstring=/password:"%pass%"
goto start

:NOPASS
REM No password entered
set pstring=


:START
cls
echo Servers
for /f "tokens=*" %%i in (Servers.txt) do (
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% ComputerSystem GET Manufacturer /value') do SET manufacturer=%%a
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% ComputerSystem GET Model /value') do SET model=%%a
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% CPU GET name /Value') do SET name=%%a
FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% Bios GET SerialNumber /value') do SET serialnumber=%%a
)
echo    %%i    %model%    %name%   %serialnumber%   %manufacturer%

goto start
jamil MohammadAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jamil MohammadAuthor Commented:
How i can tell the code to go line by line in txt file and get all server information , then it move to 2nd server and so on .... etc
0
Bill PrewCommented:
Try this, it puts the echo inside the server loop.  Also, I don't see why you would want to do the final GOTO so I commented that out as it would cause an infinite loop rereading the servers text file over and over again, querying each computer over and over...

@echo off
setlocal

REM set variables
set manufacturer=
set model=
set serialnumber=
set name=
set ustring=
set pstring=

:USERNAME
REM Get Username
set user=%username%
set /p user=[Admin Username  / Press Enter For %username%] :

REM Check If Other Username
IF NOT %user% == %username% goto newuser
goto start

:NEWUSER
REM It's A Different User
set ustring=/user:"%user%"

:PASSWORD
REM Get Password
echo Password:
set pass=
set /p pass= 

REM Check if password was entered
IF [%pass%] == [] goto nopass
set pstring=/password:"%pass%"
goto start

:NOPASS
REM No password entered
set pstring=


:START
cls
echo Servers 
for /f "tokens=*" %%i in (Servers.txt) do (
    FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% ComputerSystem GET Manufacturer /value') do SET manufacturer=%%a
    FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% ComputerSystem GET Model /value') do SET model=%%a
    FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% CPU GET name /Value') do SET name=%%a
    FOR /F "tokens=2 delims='='" %%a in ('WMIC %%i %ustring% %pstring% Bios GET SerialNumber /value') do SET serialnumber=%%a
    echo    %%i    %model%    %name%   %serialnumber%   %manufacturer% 
)

REM goto start

Open in new window


»bp
0
jamil MohammadAuthor Commented:
thanks Bill , but it doesn't work.
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Bill PrewCommented:
Can you be more specific?


»bp
0
jamil MohammadAuthor Commented:
basically, it doesn't show any output when i run the batch file.
kindly find the attached screen shot
output.jpg
0
Bill PrewCommented:
Those errors are from the WMIC command since you have the syntax wrong.  Try the following, if that doesn't work then I would suggest you test a single WMIC from a command prompt until it gives you what you want before running the BAT.  I didn't study all of your BAT file, I thought you had the other parts working...

@echo off
setlocal

REM set variables
set manufacturer=
set model=
set serialnumber=
set name=
set ustring=
set pstring=

:USERNAME
REM Get Username
set user=%username%
set /p user=[Admin Username  / Press Enter For %username%] :

REM Check If Other Username
IF NOT %user% == %username% goto newuser
goto start

:NEWUSER
REM It's A Different User
set ustring=/user:"%user%"

:PASSWORD
REM Get Password
echo Password:
set pass=
set /p pass= 

REM Check if password was entered
IF [%pass%] == [] goto nopass
set pstring=/password:"%pass%"
goto start

:NOPASS
REM No password entered
set pstring=


:START
cls
echo Servers 
for /f "tokens=*" %%i in (Servers.txt) do (
    FOR /F "tokens=2 delims='='" %%a in ('WMIC /node:%%i /user:%ustring% /password:%pstring% ComputerSystem GET Manufacturer /value') do SET manufacturer=%%a
    FOR /F "tokens=2 delims='='" %%a in ('WMIC /node:%%i /user:%ustring% /password:%pstring% ComputerSystem GET Model /value') do SET model=%%a
    FOR /F "tokens=2 delims='='" %%a in ('WMIC /node:%%i /user:%ustring% /password:%pstring% CPU GET name /Value') do SET name=%%a
    FOR /F "tokens=2 delims='='" %%a in ('WMIC /node:%%i /user:%ustring% /password:%pstring% Bios GET SerialNumber /value') do SET serialnumber=%%a
    echo    %%i    %model%    %name%   %serialnumber%   %manufacturer% 
)

REM goto start

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.