Created
January 2, 2024 13:22
-
-
Save kam-daniel/7362a1b4d0efb6df963d841f98f23076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal | |
set SERVER1=10.30.1.15 | |
set SERVER2=10.30.1.16 | |
for %%i in (%SERVER1%, %SERVER2%) do ( | |
call :logoffUser %%i | |
) | |
exit /b | |
:logoffUser | |
set SERVER=%1 | |
for /f "tokens=1,2,3,4 delims= " %%a in ('quser /server:%SERVER%') do ( | |
if /i "%%a"=="%USERNAME%" ( | |
set SESSION_ID=%%b | |
goto :logoffSession | |
) | |
if /i "%%c"=="%USERNAME%" ( | |
set SESSION_ID=%%d | |
goto :logoffSession | |
) | |
) | |
:logoffSession | |
if not defined SESSION_ID ( | |
echo Session ID not found for %USERNAME% on server %SERVER%. | |
exit /b | |
) | |
logoff %SESSION_ID% /server:%SERVER% | |
echo Logged off session ID %SESSION_ID% for %USERNAME% on server %SERVER%. | |
exit /b | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment