We help IT Professionals succeed at work.

ADFind Query To Find Last Logon of User

itsmevic
itsmevic asked
on
Hi Experts!

   I think I'm fairly close to figuring the syntax out here but need a little assistance.   Trying to pull active users in AD and their last logon time stamp.  Here's what I have so far:

adfind -default "&(objectcategory=person)(objectclass=user)(!userAccountcontrol:AND:=2)* samaccountname userprincipalname displayname lastlogontimestamp -csv -tdca > C:\xxxx\xxxxx\desktop\LastLogon.csv

Open in new window

Comment
Watch Question

Top Expert 2013
Commented:
hey mevic,  close try (added the -bit and -f switches, and a quote at the end of the filter)


adfind -default -bit -f "&(objectcategory=person)(objectclass=user)(!userAccountcontrol:AND:=2)" samaccountname userprincipalname displayname lastlogontimestamp -csv -tdca > C:\xxxx\xxxxx\desktop\LastLogon.csv

How does that work

Thanks

mike
Dont know if you ADfind is a must but another easy way of doing this is using the quest AD cmdlets.

The command would be

get-qaduser -includeallproperties | select-object name,lastlogontimestamp >c:\file.txt
Top Expert 2013

Commented:
Hey xxd, I think the only thing missing from the powershell command is the -enabled switch, then they both work

Author

Commented:
That did it, thank you again Mike.  Wonder if there is a good book I can buy or a really good reference site that you know of that I can use?  I almost feel like I'm bugging you with this piddly stuff everytime I need to query something.
Top Expert 2013

Commented:
It's fine, you are not a bother  I'm glad to help and you are going to be answering these questions yourself in no time.

As far as books the AD Cookbook by O'Reilly (Larua Huner author, she used to post here a lot too) as a lot of good examples.  I'd recommend that one, and just trial and error.

One book that I really hope for is  http://blog.joeware.net/2010/02/05/1898/   hope Joe has time for that.

Keep up the good work.

Thanks

Mike
Didn't see the part about only active users. Trying to put what chris-dent showed me last time to good use

Author

Commented:
Good stuff Mike, thank you.  I'm assuming your talking Laura Hunters book here ---> http://www.amazon.com/Active-Directory-Cookbook-Robbie-Allen/dp/059610202X/ref=sr_1_1?ie=UTF8&s=books&qid=1276639731&sr=1-1

Oh and yeah if Joe can get that book published, I'll be first in line to get that for sure!  Thank you again ( :

Top Expert 2013

Commented:
Yeah that is the book, there is a newer version out (3rd edition)  

http://www.amazon.com/Active-Directory-Cookbook-2008-publication/dp/0596521103/ref=sr_1_1?ie=UTF8&s=books&qid=1276645338&sr=1-1

Good deal there used too.

Thanks

Mike