I know that getting out of a nested loop is pretty simple, however I'm not sure how to do this when I work with multiple server lists. Here's the script:
Purpose: to search for sessions on the server that match a specific user ID, as well as to destroy all disconnected sessions found
Problem: I have several farm lists. I want to cycle through the lists until I find a user session, and then stop when this list is completed (it does not stop when the session is cleared, they may have several sessions in the farm).
Farmlist1.txt farmlist2.txt farmlist3.txt
If the session is found in the farmlist2.txt file, I want to end the search in this list, but do not continue the farmlist3.txt file.
That's what I still have, and it works like a charm. (Optimization is welcome)
@echo off
echoCitrix Session Reset
echo.
echo This will look for a specific userID AND kill disconnected sessions on all servers!
set /p userid=User ID of the user:
for %%a in (q:\scripts\1common\citrixlists\*.txt) do (
for /f "tokens=*" %%l in (%%a) do (
ping %%l -n 1 | find /i "TTL=" > nul
if errorlevel 1 (
echo server %%l down or out of Load
) else (
echo Looking for %username% and killing disconnected sessions on %%l
for /f "tokens=3" %%b in ('qwinsta *tcp /server:%%l ^| find /i "%userid%"') do echo %%b | rwinsta %%b /server:%%l && echo SESSION FOR %userid% KILLED ON %%l
for /f "tokens=2" %%i IN ('qwinsta /server:%%l ^| find /i "disc"') DO (
if %%i gtr 0 (
rwinsta %%i /server:%%l && echo Disconnected sessions terminated
)
)
)
)
)
source
share