1.

Solve : FOR /F to search computer name in a text file and report to another text file.?

Answer»

I need to check the computer names in the text file for a string then report back to another text file with the results.

Not sure the correct 'command to run' in the For /F statement after do, maybe I should use RUN and not START???

for /f "tokens=*" %%j in (C:\folder\file.txt) do (START "" \\Server\Share\filever.exe" "C:\Program Files (x86)\Microsoft Office\x\file.dll" |findstr "x.x.x.x"
if %errorlevel% EQU 0 (
echo %computername% %date% %time% Software Installed >> "\\Server\Share\Software.txt")

exitAre you saying the computer names are in file.txt?I've read and reread the question and example code.. and something is missing to help me even understand what you're asking to do.. PLUS, the code given has mis-matched ()'s, so it won't execute properly regardess.

The only thing I do understand.. There is no "RUN" command in batch files. And the START command is to launch a program as a separate process. Try typing "start cmd" to see what I mean.. You'll end up with another command console prompt.

From the code, I'm *guessing* you want to run through a list of computer names and check if something is installed on each computer name given.. ?Hi, sorry for the delay.

OK, I thought I could do it this way but I have an error with the FOR /F syntax in the first line, if I REM out the first line the script works??

REM for /f "tokens=*" %%a in (C:\Folder\Computerlist.txt) do (
"\\Server\Share\filever.exe" "C:\Program Files\File.dll" |findstr "x.x.x.x"
if %errorlevel% EQU 0 (
echo %computername% %date% %time% Software Installed >> "C:\Folder\Report.txt"
goto:eof
)
eof

So I am doing something wrong in the first line of the file, is doesn't do anything, it should check through the Computerlist.txt file which has all the computer names in it, and check for a specific *.dll file and if there is no error it should put the computername, date and time in the Report.txt file. Note, I didn't put the full path of where the *.dll file exists, too long.

This will work if I REM out the first line so I must be using the FOR /F command wrong??

Thanks again for the help.Does the title " SEARCH computer name in a text file and report to another text file" represent what you want to to?
Is this homework?
Why do you need this?

Have you done this:

Code: [Select]C:\find /?
find can do most or all of what you need.


Quote from: Newbie0000 on November 24, 2015, 11:33:57 AM

I have an error with the FOR /F syntax in the first line, if I REM out the first line the script works??

You invoke the FOR metavariable %%a in the FOR /F line, but then you never use it in the loop. %%a will successively hold each of the lines in C:\Folder\Computerlist.txt but, as I say, you don't use it. Did you expect %computername% to hold something different each time around the loop? (that variable is a special one used by Windows to hold the host name of the local computer).



Thank you, I forgot to get it to loop through the text file I guess, I will try to fix that.Geek-9pm

I deployed software via GPO and now I need to see how many installs where successful so it will search the text file with the computer names and report back for each computer. I used a DSQuery for computers in certain OU's to DEPLOY the software via GPO.Your information is to little, and whats your purpose of you using the string...? maybe this is what your looking for.
it's not tested but it should be error free

@echo off
color 17
title Made by Zask

SET /p "Command1= Creating directory, what would you like to name it? : "
set /p "Command2= Name of file 1. : "
set /p "Command3= Name of file 2. : "

if not exist "C:\%Command1%\" (
mkdir "C:\%Command1%\"
if "!errorlevel!" EQU "0" (
echo Folder created successfully
) else (
echo Error while creating folder
)
) else (
echo Folder already exists
)

copy /Y "%~f0" "C:\%Command1%"
set nl=^& echo.
echo %nl% %nl% %nl%

echo @echo off >> C:\%Command1%\%Command2%.txt
echo echo @echo off ^>^> C:\%Command1%\%Command3%.txt >> C:\%Command1%\%Command2%.txt
echo echo %%date%% ; this is the variable for date ^>^> C:\%Command1%\%Command3%.txt >> C:\%Command1%\%Command2%.txt
echo echo %%time%% ; this is the variable for time ^>^> C:\%Command1%\%Command3%.txt >> C:\%Command1%\%Command2%.txt
echo echo %%computername%% ; this is the variable for the computer name ^>^> C:\%Command1%\%Command3%.txt >> C:\%Command1%\%Command2%.txt
echo echo %%username%% ; this is the variable for user name ^>^> %Command1%\%Command3%.txt >> C:\%Command1%\%Command2%.txt

echo null >> C:\%Command1%\Dont_remove!.tmp
echo Files Created!
pause

:2
set /p "Command4= Start your folder (y/n). : "

if %Command4%==y goto 3
if %Command4%==n goto 4

:3
start C:\%Command1%
:4
echo About to create second file!
pause

cd C:\%Command1%\
ren *.txt *.bat
echo %nl% %nl% %nl%
call %Command2%.bat
echo %nl% %nl% %nl%
del /s *%command2%.bat

echo Second file created!
pause

:end
Thank you for the help, I am looking through computer names in a text file to check each computer for a certain string that will tell me if the software I sent out via GPO was installed successfully and put the outcome in a file called Report. I found something that worked for me:

@ECHO OFF
FOR F "usebackq tokens=*" a IN ("c:\Folder\ComputerNames.txt") DO (
"\\Server\Share\filever.exe" "\\a\C$\Program Files\File.dll" | findstr "1.2.3.4"
&& echo a %date% %time% Software Installed >> "C:\Folder\Report.txt"Quote from: Newbie0000 on December 12, 2015, 04:13:46 AM
Thank you for the help, I am looking through computer names in a text file to check each computer for a certain string that will tell me if the software I sent out via GPO was installed successfully and put the outcome in a file called Report. I found something that worked for me:

@ECHO OFF
FOR F "usebackq tokens=*" a IN ("c:\Folder\ComputerNames.txt") DO (
"\\Server\Share\filever.exe" "\\a\C$\Program Files\File.dll" | findstr "1.2.3.4"
&& echo a %date% %time% Software Installed >> "C:\Folder\Report.txt"

So you no longer need my help?


Discussion

No Comment Found