• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 44
  • Last Modified:

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
0
jamil Mohammad
Asked:
jamil Mohammad
  • 3
  • 3
1 Solution
 
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now