Confirming computer exists under all domain controllers in a domain?

Christopher Compton 1 Reputation point
2023-01-05T23:37:59.48+00:00

I am trying to create a PowerShell script that will confirm what domain controllers are seeing a computer that I am joining to the domain. The reason being is I would like it as a tool to troubleshoot trust relationship issues with computers that are having difficulty joining the domain. I'm unsure how I would go about checking. Obviously I could use something like:

get-addomaincontroller -filter * | Select name

This could be run from the target computer to see all listed domain controllers. But I would more so like to be able to search domain controllers filtering by the computer name of the computer in question because I am mostly troubleshooting the trust issues remotely.

Anybody have any ideas?

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,849 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,362 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2023-01-05T23:52:34.133+00:00

    Get a list of all DCs and use that in a ForEach-Object loop. Use the Get-ADComputer cmdlet to look for the computer name in the filter and add the "-Server" parameter using the name of the DC in the iteration of the loop.

    But this isn't going to help you troubleshoot trusts, or replication. There are GUI and command line tools for that. Here's one of each:

    get-use-active-directory-replication-status-tool
    repadmin-how-to-check-active-directory-replication

    If you want to use PowerShell, there are ways to do that, too: 326364

    0 comments No comments

  2. Andreas Baumgarten 96,266 Reputation points MVP
    2023-01-06T00:10:19.013+00:00

    Hi @Christopher Compton ,

    maybe something like this helps to get started:

    $computer = "test1"  
    Get-ADDomainController | ForEach-Object {  
      try {  
        $compObj = Get-AdComputer -Identity $computer -Server $_.Name -ErrorAction SilentlyContinue  
        if ($compObj) {  
          Write-Host "Computer $computer found on DC $_" -ForegroundColor Green  
        }  
      }  
      catch {    
        Write-Host "($_)" -ForegroundColor Red  
      }  
    }  
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments