Finding Domain Controllers
Domain Controllers are the keys to the kingdom as far as AD is concerned. Once we can find them we can do all sorts of stuff. So how do we find them?
if (-not (Get-Module ActiveDirectory)){
Import-Module ActiveDirectory
}
$ou = "OU=Domain Controllers,DC=Manticore,DC=org"
"`nMicrosoft"
Get-ADDomainController -Filter * | Format-Table Name, ComputerObjectDN
"`nAD provider"
Get-ChildItem -Path Ad:\$ou | Format-table
"`nQuest"
Get-QADComputer -ComputerRole "DomainController"
"`nScript"
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$domain.FindAllDomainControllers() | select Name
The code using the provider assumes that the domain controllers have been left in the default location – you shouldn’t move them – otherwise the the techniques will retrieve them based on AD information