Child domains and how to target their DCs

I’ve moved on to a much larger site with work and the environment is lot more complex that I’ve dealt with previously.

I had a requirement today to check all the Domain Controllers and needed a powershell script to identify the DCs in each child domain.

A quick bit of research and hacking together of some snippets and viola:

import-module activedirectory

$Domains = (Get-ADForest).Domains

foreach ($Domain in $Domains) {

$PDC = Get-ADDomainController -Discover -Domain $Domain | Select-Object name
$Where = $Domain + " " + $
$Where #Prints the current PDC that is being queried

$AllDCs = Get-ADDomainController -server $ -Filter * | select name

foreach ($dc in $AllDCs) {

$testdc = $ + "." + $Domain
$Text = "Testing " + $TestDC
$text #Prints the current DC being targeted - insert whatever code is required after this



Leave a Reply