Skip to main content
deleted 246 characters in body
Source Link

This should work

**names.txt**
host1
host2
host3

**chk1**check.bat**
@echo off
setlocal EnableDelayedExpansion
FORset /F "tokens=* delims="p %%xname=Enter inthe (names.txt)host DOname (
setFINDSTR name=%%x
call/L chk2.bat/C:%name% 


**chk2names.bat**txt
@echoIF off
setlocal%ERRORLEVEL% EnableDelayedExpansion
IFEQU /I0 name==%FQDN%echo "found" ELSE echo "match"not found"
pause

The 1st batch file would call the 2nd batch file which performs the check. Unfortunately Batch files don't allow nesting of loops (or even including IF statements inside a FOR loop)

**names.txt**
host1
host2
host3

**chk1.bat**
@echo off
setlocal EnableDelayedExpansion
FOR /F "tokens=* delims=" %%x in (names.txt) DO (
set name=%%x
call chk2.bat 


**chk2.bat**
@echo off
setlocal EnableDelayedExpansion
IF /I name==%FQDN% echo "match found"
pause

The 1st batch file would call the 2nd batch file which performs the check. Unfortunately Batch files don't allow nesting of loops (or even including IF statements inside a FOR loop)

This should work

**names.txt**
host1
host2
host3

**check.bat**
@echo off
setlocal EnableDelayedExpansion
set /p name=Enter the host name 
FINDSTR /L /C:%name% names.txt
IF %ERRORLEVEL% EQU 0 echo "found" ELSE echo "not found"
pause
Source Link

**names.txt**
host1
host2
host3

**chk1.bat**
@echo off
setlocal EnableDelayedExpansion
FOR /F "tokens=* delims=" %%x in (names.txt) DO (
set name=%%x
call chk2.bat 


**chk2.bat**
@echo off
setlocal EnableDelayedExpansion
IF /I name==%FQDN% echo "match found"
pause

The 1st batch file would call the 2nd batch file which performs the check. Unfortunately Batch files don't allow nesting of loops (or even including IF statements inside a FOR loop)