i wrote this script to avoid being locked out of active directory after changing my password and still being logged in on a file server. the script requires two parameters. the first parameter is a text file containing a list of servers (you code probably write an adsi script to generate this list automatically). the second parameter is the username to check against.

the script depends on qwinsta (a binary command based on “query session”) which is part of the terminal services command suite, so should exist on windows xp.

whereAmI.bat:

@ECHO OFF
:: whereAmI.bat - tries to identify which server you are logged into

:: needed for nested loops
SETLOCAL ENABLEDELAYEDEXPANSION
CLS

:: error handling
IF "%1" == "" GOTO errNoServerList
IF "%2" == "" GOTO errNoUserName

SET ServerList=%1
SET User=%2

ECHO Checking to see where you are logged on, please wait.

FOR /F %%C IN (%ServerList%) DO (
	qwinsta /server:%%C | findstr /i %User% > NUL
	IF !ERRORLEVEL! EQU 0 ECHO You are logged on %%C
)

ECHO Search complete!
GOTO theEnd

:errNoServerList
ECHO Error: Must provide a text file containing list of servers
ECHO Format of server list
ECHO ServerName1
ECHO ServerName2
ECHO ServerNameYadaYadaYada
GOTO theEnd

:errNoUserName
ECHO Error: You must provide a user name to search against
ECHO Example usage:
ECHO.
ECHO %0% whereAmI.lst UserID
GOTO theEnd

:theENd
Tagged with:
 

Comments are closed.