I'm trying output a echo based on first four characters of multiple computer names. Here is what I have so far but it's not working. Code: @echo off SET Name=%computername% SET FirstFourChars=%computername:~0,4% FOR %%A IN (aaaa bbbb cccc dddd eeee) DO IF %%A==%FirstFourChars% echo Test 1 FOR %%A IN (ffff gggg hhhh jjjj kkkk) DO IF %%A==%FirstFourChars% echo Test 2 exit
not really enough info to diagnose - so ill take some guesses from the top, any reason for the unused Name envvar? second %COMPUTERNAME% tends to be all uppercase - if youre comparing it against lowercase strings that might be your issue try enabling command extensions at the beginning of your batch Code: SETLOCAL ENABLEEXTENSIONS and doing case insensitive compare in your IF statements Code: ... IF /I %%A EQU %FirstFourChars% echo Test 1