I have active directory configured in windows server 2012 r2. I want to collect logs of a particular user or Multiple users. The logs must show the login time, logout time, system operating system, IP address etc of last 10 days or more. How can I do it?

  • What have you tried? Have you done an Internet search for ideas? Please edit these answers into your question. Commented Apr 7, 2017 at 15:26

1 Answer 1


There's some good scripts in the Script Centre for this type of stuff. This one may suit your needs: http://community.spiceworks.com/scripts/show/89-track-login-and-logout-vbs

How to Audit Successful Logon/Logoff and Failed Logons in Active Directory https://www.lepide.com/blog/audit-successful-logon-logoff-and-failed-logons-in-activedirectory/

If you just want the last login for each user then use:

@echo off for /f "tokens=2 delims=:" %%a in ('ipconfig ^|find "IP Address"') do call :process %%a & goto :next :next echo You are on subnet %subnet% with address %ipaddress% echo %date%,%time%,%computername%,%username%,%ipaddress% >\server\share$\lastuser\%computername%.txt

exit /b

:process for /f "tokens=1-4 delims=." %%a in ("%1") do (set subnet=%%a.%%b.%%c)&(set host=%%d)&(set network=%%c) set ipaddress=%subnet%.%host% exit /b

Then add a shortcut on your desktop or whatever to a batch file as:

type \server\share$\lastuser*.txt > "%temp%\allcomputers.csv" start excel "%temp%\allcomputers.csv"


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .