Techibee.com

PowerShell Commands to list domain controllers in Domain.

My previous article talks about listing domain controllers in a domain in non-powershell world. But with introduction of powershell things changed a lot to give more flexibility to system administrators and developers.
 Below piece of powershell code helps to you get it.
 List domain Controllers in domain:
$localdomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$localdomain | % { $_.DomainControllers } | Select name
  

List all domain controllers in forest

 

$localdomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()$localdomain.forest.domains | % { $_.DomainControllers } | Select name

You can count the no. of domain controllers also.

 

($localdomain.forest.domains | % { $_.DomainControllers } | Select name).count
Happy Learning..,
Sitaram Pamarthi
Exit mobile version