I am trying to make a batch file that will go through a text file of computer names and get the username that is logged in on each. I am not sure how to set the variables I need within the loops. I have tried several of the solutiions that I have found on here but none of them seem to work. output.txt contains:
PCHTW-HTT10425
PCHTW-HTT10437
These are the computer names that I am trying to pass. When I echo %%A
it gives the names, but setting name to %%A does nothing. Reading up on it I thought adding in the SETLOCAL EnableDelayedExpansion
would do the trick but it appears to have done nothing. I have also tried echo name:!name!
but it also doesn't work.
for /F "tokens=*" %%A in (%FILEPATH%output.txt) do (
setlocal EnableDelayedExpansion
echo %%A
SET /p name=%%A
echo name:%name%
FOR /F "tokens=2 delims=\" %%F IN ('wmic /NODE:"%name%" computersystem get UserName') DO (
SET username=%%F
)
echo %username%
pause
ENDLOCAL
)