Friday, June 28, 2013

How To Use DsQuery



In Active Directory there are ample numbers of the command line tools/utility which we can used to relate with Active Directory, such as DsMOD, DsQuery, DsGet, NetDom etc….

Now I’m using DsQuery command 

Dsquery is a command-line tool that is built into Windows Server 2008. It is available if you have the Active Directory Domain Services (AD DS) server role installed. To use dsquery, you must run the dsquery command from an elevated command prompt. To open an elevated command prompt, click Start, right-click Command Prompt, and then click Run as administrator.

Which can query for any type of object:

dsquery computer – finds computers in the directory.
dsquery contact – finds contacts in the directory.
dsquery subnet – finds subnets in the directory.
dsquery group – finds groups in the directory.
dsquery ou – finds organizational units in the directory.
dsquery site – finds sites in the directory.
dsquery server – finds AD DCs/LDS instances in the directory.
dsquery user – finds users in the directory.
dsquery quota – finds quota specifications in the directory.
dsquery partition – finds partitions in the directory.

To find all the domain controllers in the forest with DN and RDN:
  • DsQuery Server -o RDN -Forest
  • DsQuery Server -Forest
To find all the domain controllers in a domain:
  • DsQuery Server -domain domain_name.com
To list all the domain controllers in a domain that is also Global Catalog Servers:
  • DsQuery Server -domain domain_name.com -isgc
To list the domain controller in the forest that holds the Schema FSMO:
  • DsQuery Server -Forest -hasfsmo schema
Use the ">" to store the output to a text file. The below command will store all the domain controller names in AllDCs.txt.
  • DsQuery Server -Forest > AllDCs.txt

Retrieve a List of Groups

Dsquery group DN

For example, the following command retrieves a list of all groups in the Sales OU 

C:\>dsquery group "ou=sales,dc=dinesh,dc=singh,dc=com" 
"CN=G_Sales,OU=Sales,DC=dinesh,DC=singh,DC=com"
"CN=G_SalesAdmins,OU=Sales,DC=dinesh,DC=singh,DC=com"
"CN=G_NorthSalesAdmins, OU=South,OU=Sales,DC=dinesh,DC=singh,DC=com"


C:\>dsquery group "ou=sales,dc=dinesh,dc=singh,dc=com" > group.txt


 Please share your valuable feedback for improvement :)

No comments:

Post a Comment