O R G A N I C / F E R T I L I Z E R: list domain controllers with powershell

Oct 6, 2009

list domain controllers with powershell

for my own edification and later reference.

to start, let's grab the current domain.
$myDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

just for fun, we’ll look at the forest.

now, let’s list the domains of the forest.

this will count every domain controller in every domain.
$myDomain.Forest.Domains | % { $_.DomainControllers.Count }

for a final count, we’ll add all the numbers together into $myCount.
$myDomain.Forest.Domains | % { $myCount = $_.DomainControllers.Count + $myCount}

to list all of the domain controllers, we can run this command.
$myDomain.Forest.Domains | % { $_.DomainControllers } | Select-Object name

finally, another way to count all of the domain controllers in the forest.
($myDomain.Forest.Domains | % { $_.DomainControllers } | Select-Object name).count