List all Domain Controllers in Domain

Get-AdDomainController cmdlet in PowerShell use to get list of domain controllers in domain in Active Directory. As administrators, it’s very important to know resources in an active directory and manage an active directory efficiently.

Get-AdDomainController gets the domain controller specified by Identity, Filter, or Discover parameter. There are other ways to get list of domain controllers in domain using Get-ADGroupMember, Get-AdForest cmdlet in PowerShell.

In this article, I will show you how to get list of domain controllers using the Get-AdDomainController cmdlet in PowerShell.

List all Domain Controllers in Domain

To get list of domain controllers in domain use the Get-AdDomainController cmdlet in PowerShell as below

$DomainName = (Get-ADDomain).DNSRoot
$DCList = Get-ADDomainController -Filter * -Server $DomainName | Select-Object Hostname,Site,OperatingSystem

In the above PowerShell script, Get-AdDomain PowerShell cmdlet gets AD domain name and stored in variable $DomainName.

The second command, Get-AdDomainController cmdlet uses the Server parameter to list all domain controllers in the specified domain name and passes the object to select HostName, Site, and OperatingSystem.

The output of the above script to get list of domain controllers is given below

List all Domain Controllers in Domain
List all Domain Controllers in Domain

Get all Domain Controllers using Get-AdGroupMember

You can use the Get-AdGroupMember cmdlet in PowerShell to get all domain controllers in the domain as given below

Get-ADGroupMember 'Domain Controllers'

This command uses the Get-AdGroupMember cmdlet to get all domain controllers, output is given below

distinguishedName : CN=ENGG-PRO,OU=Domain Controllers,DC=SHELLPRO,DC=LOCAL
name              : ENGG-PRO
objectClass       : computer
objectGUID        : dbf93c91-4f31-401e-b924-88cfed6b16c0
SamAccountName    : ENGG-PRO$
SID               : S-1-5-21-1426734019-4042446242-464921959-1000

List all Domain Controllers in Forest

You can use the Get-AdForest cmdlet in PowerShell to list all domain controllers for all domains in a forest as given below

$DCList = (Get-ADForest).Domains | %{ Get-ADDomainController -Filter * -Server $_ }

In the above PowerShell cmdlet, Get-AdForest cmdlet gets all domains in a forest and passes the output to the second command.

The second command uses Get-AdDomainController to list all domain controllers for all domains in a forest.

Nltest to list all Domain Controllers

Nltest is a command-line tool used to list all domain controllers in a domain.

Run below command as below

nltest /dclist:SHELLPRO.LOCAL

This command gets all domain controllers in the domain name SHELLPRO.LOCAL

Cool Tip: How to check FSMO roles holders using PowerShell!

Conclusion

I hope the above article on how to list all domain controllers in the domain is helpful to you.

Get-AdDomainController cmdlet in PowerShell is used to get a list of domain controllers, IP information. You can use other commands like Get-AdForest, nltest to list all domain controllers.

Cool Tip: How to use get-adprincipalgroupmembership in Active Directory!

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Leave a Comment