PowerShell and list of all DC in forrest

Sometime, when I tried solve problems with Exchange Server on-permises I need i.e. investigate traffic for Active Directory. Or when I need set up new site. And for many other cases. For mall environments it’s simple: open dsa.msc also known for ADUC and look. For bigger, it’s quite complicated :).

DirectoryServices

That method is kind of strange, as it actually return metadata of servers, not actually servers. :)

$Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$Forest.Sites | % { $_.Servers } | Select Name, Domain

via Technet forum

ActiveDirectory module

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

via docs.microsoft.com

References

  • https://social.technet.microsoft.com/Forums/windowsserver/en-US/3553139c-7ecf-4637-9f2b-7129323aa405/how-do-i-get-list-for-all-dcs-for-the-entire-forest?forum=winserverDS
Written on July 3, 2018