Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOS 1

Status
Not open for further replies.

GrimR

IS-IT--Management
Jun 17, 2007
1,149
ZA
I know this is not vbscript it's old school batch file, but I cant find where else to post. Please see if you can help anyway, thanks
I am trying to go through the array, if the PC name is found it goes to the section found it else goes to RunMe
I can get it to echo out the names but as soon as I try and make it EQU %ComputerName% something does not work.



Code:
@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

set TARGETMACHINE=G-13-24,G-13-25,G-13-26,IT-PC

for %%i in (%TARGETMACHINE%) do ( @set 
	  ::echo %%i
	  IF %COMPUTERNAME%  ==  %%i (goto FoundIT) ELSE (goto RunMe)
	
	)
)
:RunMe

echo You are not in the list this will run

goto end

:FoundIT
	   
echo Found you, nothing to do


:end
pause

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Everything works, but the logic of your script was wrong, because you escape the loop after 1. non succesfull iteration. Try this
Code:
@echo off

SETLOCAL ENABLEDELAYEDEXPANSION

set TARGETMACHINE=G-13-24,G-13-25,G-13-26,IT-PC

for %%i in (%TARGETMACHINE%) do ( 
	  ::echo %%i
	  if %COMPUTERNAME%  ==  %%i goto FoundIT
)
echo You are not in the list this will run
goto end

:FoundIT	   
echo Found you '%COMPUTERNAME%' , nothing to do.

:end
pause
 
Thanks for the help works perfectly.

MCITP:EA/SA, MCSE, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top