Search a computer across all Domain Controllers

Search a computer across all Domain Controllers isn’t something I had to do in the past, but once, I had a little issue with a machine saying it was joined to a domain but it wasn’t in AD, even if the machine was joined 5 minutes earlier. I thought that perhaps it hit another Domain Controller and it was slowly replicating (this wasn’t the case). Still, out of curiosity I thought it’d be good to search a computer across all Domain Controllers; this is also a good option to see how fast the DCs are replicating content against each other.

Here’s the little script in Powershell:

Note: -ErrorAction Silently continue cannot be used with Get-ADComputer. To avoid getting errors every time the computer isn’t found on a certain Domain Controller I used Try/Catch. As you can see it tries (Try{}) to run the Get-ADComputer command, but if it returns an error, it’ll execute whatever is in Catch{}.

2 thoughts on “Search a computer across all Domain Controllers

  1. Hi, This does work great. One thing I did notice if the DC did not respond to the Powershell query (if there was an issue) it marks that as does not exist.

    1. Hi AL, You’re right. That’s a very, very basic example of how you could build something up. Ideally you’d want the output to a CSV or something. To avoid the “problem” you’re having, you could include the Try/Catch into an If statement (Test-Connection $dc -Count 1). That’ll ping the DC before trying to grab data off it. Then you can also add an Else to that If statement and write a different message, something like “$($dc) not reachable.”. Hope this clarify a bit more, let me know if you still have troubles and I can add this bit of code in another example.

Leave a Reply

Your email address will not be published. Required fields are marked *