How can I use the Windows Server 2003 command line to find all users in a domain who match certain criteria?

John Savill

October 8, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A. The Dsquery command lets you query Active Directory (AD) for most types of objects based on passed attributes. To see the full list of options, type

dsquery user /?

The basic command syntax is

dsquery user  

For example, to find all users whose name starts with the letter "J" in domain it.uk.savilltech.com, I typed

dsquery user DC=it,DC=uk,DC=savilltech,DC=com -name J*

and the system returned

"CN=John,CN=Users,DC=it,DC=uk,DC=savilltech,DC=com""CN=James,CN=Users,DC=it,DC=uk,DC=savilltech,DC=com""CN=Jim,CN=Users,DC=it,DC=uk,DC=savilltech,DC=com"

To find all users who hadn't changed their password in more than 10 days, I typed

dsquery user DC=it,DC=uk,DC=savilltech,DC=com -stalepwd 10

To find all users who hadn't logged on using their password in the past week, I typed

dsquery user DC=it,DC=uk,DC=savilltech,DC=com -inactive 1

You can also combine switches, if necessary. For example, to find all users whose name starts with the letter "J" and who hadn't changed their passwords in more than 10 days, I typed

dsquery user DC=it,DC=uk,DC=savilltech,DC=com -name J* -stalepwd 10

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like