PowerShell - Search Across Multiple Domains in a Forest

2012, Feb 07    

While trying to find a quick answer to search across domains for duplicated user accounts, I came across a blog (sourced) that pointed me in a good direction.  To skip the meat of it, we have a Global Catalog setup on our AD and I found it more useful to target that and search the entire forest, then to attach to each domain individually.  I hope this helps others out there in a similar scenario…

The above code will return you all Domain User Accounts in the Forest with the SamAccountName of user0123.  If you’re like me, you’ll want to handle the results from FindAll() instead of just dumping it to the pipeline:

As you can see, I’ve moved the FindAll() method to the foreach conditional for handling. Of course, I’m still dumping the results to pipline, but it’s a nice, clean object that is pre-formatted just the way I want it.

I hope this helps others out there!