Query Active Directory for Last Logon/Authentication Date

coolsport00
coolsport00 used Ask the Experts™
on
My Question Title says it all. I did a brief search here on EE but didn't find what I was needing. I have a W2K3 domain and would like to query all DCs to find last logon date/time for all users. This is for obvious reasons...I've been at my company x 3yrs and there seems to be some legacy user accounts I want to disable/delete, but wanted to perform some basic 'checks' before doing so to see if they are still used. I'm hoping this is either a simple .bat file, .vbs file, or whatever that can be placed in a txt or csv.

Thank you in advance....let me know if you need anything further.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013
Commented:
A few ways to get rid of stale accounts the first and what I like the best is old computer by Joe Richards.  Works for users too.
http://www.joeware.net/freetools/tools/oldcmp/index.htm
oldcmp -report -users -llts
That will give you a nice report of users > 90 days.  Since you are at 2003 DFL you can query the lastlogontimestamp (-llts switch)
If you want a report in excel you can use oldcmp but I also like adfind by Joe Richards too
http://www.joeware.net/freetools/tools/adfind/index.htm
adfind -default -f  "&(objectcategory=person)(objectclass=user)" samacountname lastlogontimestamp -tdcas -csv  > c:users.csv

 Thanks
Mike
Top Expert 2010

Author

Commented:
Will try in the a.m. Mike and let you know...gracias! :)

~coolsport00
Top Expert 2013

Commented:
ok let me know how it goes
one nice thing about the oldcmp html report is that you can send it off to managers -- tell them it took you hours :)
Top Expert 2010

Author

Commented:
Ha...well, it did...kinda...you know, waiting for an answer on here and all :P
Top Expert 2010

Author

Commented:
This will work fine; I think I will play around with it a bit to try and get the 'report' into a CSV so I can remove some 'unneeded' columns, but yep...this pretty much did the trick. Thanks Mike! ~C

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial