This blog post had a simple solution for getting a list of domain controllers in Powershell.

Get-ADDomainController -Filter * | Select-Object name

Although for my script I ended up dropping the Select-Object name.

foreach ($DC in (Get-ADDomainController -Filter *)) {
  $DCName = $DC.Name
  $file = (Get-Item "\\$DCName\netlogon\file.txt").LastWriteTime
  Write-Output("$DCName :: $file")
}

I used this as a (very) quick and dirty way to diagnose an AD replication issue by comparing a file’s known modify datetime with copies in the other DC’s netlogon folder.