PowerShell – Search Across Multiple Domains in a Forest

VertigoRay/ February 7, 2012/ Uncategorized/ 0 comments

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!

Leave a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*