Find AD Domain Controllers using Powershell

We can get the list of Active Directory Domain Controllers in current domain or forest using .NET classes System.Directoryservices.Activedirectory.Domain and System.Directoryservices.Activedirectory.Forest.

Note: This PowerShell script doesn’t require to import Active Directory Module since it is using the methods from .NET Framework.

Find Domain Controllers from current Domain

This script return all the Domain Controllers from current Domain

$domain = [System.Directoryservices.ActiveDirectory.Domain]::GetCurrentDomain()
$domain | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name}

List Domain Controllers from current Forest

This script return all the Domain Controllers from current Forest

$Forest = [System.Directoryservices.ActiveDirectory.Forest]::GetCurrentForest()  
$Forest.Domains | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name}

Find Domain Controllers from specific Domain

Using below PowerShell script you can search specific domain and get all the available Domain Controllers.

$domainName ="TestDomain.Com"
$Forest = [System.Directoryservices.ActiveDirectory.Forest]::GetCurrentForest()
$Forest.Domains | Where-Object {$_.Name -eq $domainName} |  
ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name}
Advertisement

1 thought on “Find AD Domain Controllers using Powershell”

Leave a Comment