Friday, January 27, 2012

DSQuery and DSGet - Active Directory command line queries

Recent versions of Active Directory have added some useful  command line options for finding users.  I’ll show a few options here:
dsquery and dsget are my two favorites
dsquery example:  Searching for a know user name to find out what container (ou) it exists in.
dsquery user -name username
The following output is returned:
“CN=username,OU=CORP,OU=Accounts,DC=na,DC=contoso,DC=com”
To find out more about this user account add the attribute option like this:
dsquery user -name username -attr *
Another command line tool for AD is dsget.  You can use dsget to find the groups for a particular user like this: 
dsget user  ”CN=username,OU=CORP,OU=Accounts,DC=na,DC=contoso,DC=com” -memberof

No comments:

Post a Comment