Link to home
Start Free TrialLog in
Avatar of itsmevic
itsmevicFlag for United States of America

asked on

ADFind Query To Find Last Logon of User

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

ASKER CERTIFIED SOLUTION
Avatar of Mike Kline
Mike Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Hey xxd, I think the only thing missing from the powershell command is the -enabled switch, then they both work
Avatar of itsmevic

ASKER

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.
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
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 ( :

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