How To Use DsQuery To Find All The Domain Controllers In The Domain or Forest?

by [Published on 1 Oct. 2009 / Last Updated on 4 April 2009]

This article explains DsQuery commands which you can use to find all the domain controllers.

There are many command line tools which can be used to interact with Active Directory. These command line tools are DsMOD, DsQuery, DsGet etc. This article explains DsQuery command line tool and hows how you can use this command line tool to get the list of domain controllers based upon your requirement.

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

To list all the domain controllers in a domain that are also Global Catalog Servers:

  • DsQuery Server -domain -isgc

To list the domain controller in the forest that holds the Schema FSMO:

  • DsQuery Server -Forest -hasfsmo schema

Note: 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

See Also

The Author — Nirmal Sharma

Nirmal Sharma avatar

Nirmal Sharma is a MCSEx3, MCITP and was awarded the Microsoft MVP award in Directory Services and Windows Networking. He specializes in Microsoft Azure, Office 365, Directory Services, Failover Clusters, Hyper-V, PowerShell Scripting and System Center products. Nirmal has been involved with Microsoft Technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites and contributing to PowerShell-based Dynamic Packs for www.ITDynamicPacks.Net solutions.

Featured Links