Software >> OS >> Windows >> Command Line >> Active Directory >> How to use dsquery and dsget to query AD information

Assume following domain main.xyz.edu staff.main.xyz.edu student.main.xyz.edu 1. List all staff account in XYZ's staff domain dsquery user dc=staff,dc=main,dc=xyz,dc=edu -scope subtree -o samid -limit 10000 2. List all student account in XYZ's student domain dsquery user dc=student,dc=main,dc=xyz,dc=edu -scope subtree -o samid -limit 30000 3. List users matching a filter with their samaccountname, givenname and create date dsquery * dc=staff,dc=main,dc=xyz,dc=edu -scope subtree -limit 1000 -filter GivenName=A* -attr samaccountname givenname WhenCreated 4. List all users for a domain with their samccountname, givenname, and create date dsquery * dc=staff,dc=main,dc=xyz,dc=edu -scope subtree -limit 1000 -attr samaccountname givenname WhenCreated 5. Use dsquery to list all users and then pipe to dsget to display the samid and display name of each user dsquery user dc=student,dc=main,dc=xyz,dc=edu -scope subtree -limit 30000 | dsget user -samid -display 6. List all the properties of a particular user in the current domain given the SAMACCOUNTNAME dsquery * -filter "(sAMAccountName=SomeUser)" -attr * 7. List all the properties of a particular user in another domain dsquery * dc=student,dc=main,dc=xyz,dc=edu -filter "(sAMAccountName=SomeUser)" -attr * 8. How to search for students from with description matching a specific pattern dsquery * dc=student,dc=main,dc=xyz,dc=edu -filter "&((objectCategory=Person) (objectClass=User)(description="*2006*"))" -attr samaccountname description 9. How to list users who must change password at next logon dsquery * dc=student,dc=main,dc=xyz,dc=edu -filter "&((objectCategory=user)(pwdLastSet=0))"