How to DSQuery enabled user who have been inactive for 90 days

Can some familiarwith DSQuery show how to run a query for
1. enabled users only
2. users who have been inactive for 90 or more days
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Matthew MillersConnect With a Mentor Commented:
You may be able to pipe the results out to dquery again:

dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(!
serAccountControl:1.2.840.113556.1.4.803:=2))" -limit 0 | dsquery user -inactive

You may want to pay attention to what Jay Jay has indicated, although this is for old computer accounts (the joeware util).
Matthew MillersCommented:
dsquery user -inactive <weeks>

I am not sure about showing if someone is enabled, you can show who is disabled by using -disabled
You may be able to do something with adfind
the inactive switch has always been hit and miss, you would be better off playing with oldcmp from joe
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

JoeyBugeyesAuthor Commented:
You're on the right track as far as what i'm looking for.  Now if only we can combine what you provided with the following to give me a list of enabled but inactive accounts.  

List all enabled user accounts: dsquery * domainroot -filter "(&(objectCategory=Person)(objectClass=User)(!userAccountControl:1.2.840.113556.1.4.803:=2))" -limit 0

Thanks for your responses so far folks.
ahhh with the correct switches it will also work for user accounts :)
JoeyBugeyesAuthor Commented:
Nice.  I knew you could port DSQuery to a DSGet, but I didn't know you could port it to another dsquery.  Very nice!  Thanks everyone for contributing.
Were you able to make this work?  I am unable to pipe the dsquery results (Enabled Accounts) into the 2nd dsquery (Inactive Accounts).  Isn't there an easy way to query for Enabled AND Inactive Accounts?
rank master my ass he didn't take 5 seconds to test his solution
This is true, the above mentioned "Accepted Solution" Does NOT work!

Still looking for a working solution
All Courses

From novice to tech pro — start learning today.