JSI Tip 6790. Who is currently logged on to your domain?

Jerold Schulman

June 2, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Using NETDOM from the Server Support Tools and Psloggedon freeware, I have scripted WhoDom.bat to generate a file of all domain users who have logged onto your domain from a domain computer.

The syntax of the report file is similar to:

JSI007 05/30/2003 21:23:42    JSIINCJenniferJSI009 06/02/2003 06:35:33    JSIINCJerry

Where JSI007 is a computer name, JSIINCJennifer is the domain user logged on from JSI007, and 05/30/2003 21:23:42 is the date / time when JSIINCJennifer logged on.

The syntax for using WhoDom.bat is:

WhoDom NetBIOSDomainName ReportFile User Password

where:

NetBiosDomainName is the NetBIOS domain name of the domain your are querying, like JSIINC.

ReportFile is the report file, like WhoDom.TXT or \ServerShareNameWhoDom.log.

User is the User ID that has permissions to run Netdom.exe on the NetBIOSDomainName domain, and has RWXD permissions on ReportFile.

Password is the password of User.

NOTE: See Another way to determine who is currently logged on to your domain.

WhoDom.bat contains:

@echo offsetlocalif {%4}=={} goto syntaxset domain=%1set report=%2set user=%3set password=%4set domain=%domain:"=%set user=%user:"=%set password=%password:"=%if exist %report% del /q %report%for /f "skip=1 Tokens=1" %%u in ('netdom.exe query /domain:"%domain%" /UserD:"%user%" /PasswordD:"%password%" DC') do call :computer "%%u"for /f "skip=1 Tokens=1" %%u in ('netdom.exe query /domain:"%domain%" /UserD:"%user%" /PasswordD:"%password%" SERVER') do call :computer "%%u"for /f "skip=1 Tokens=1" %%u in ('netdom.exe query /domain:"%domain%" /UserD:"%user%" /PasswordD:"%password%" WORKSTATION') do call :computer "%%u"endlocalgoto :EOF:syntax@echo Syntax: WhoDom NetBIOSDomainName ReportFile User Passwordendlocalgoto :EOF:computerset machine=%1set machine=%machine:"=%if "%machine%" EQU "The" goto :EOFif "%machine%" EQU "Directory" goto :EOFfor /f "Skip=1 Tokens=*" %%l in ('psloggedon "\%machine%" -l^|Find /v "goto:EOF:whocall set work=%%line:%domain%=%%if "%work%" EQU "%line%" goto :EOF@echo %machine% %line%>>%report%

See What domain computers do not currently have domain users logged on?



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like