powershell, recursively get AD users excluding certain groups

J C used Ask the Experts™
I need to recursively collect AD users for a list of groups but if I encounter a group that is a nested member that is in my $ExclusionList I do not want to add those to the $RecursiveMembers collection.

I know how to build the recursive collection but how can I add only the users in the non excluded groups to the collection, how do I append the collection ?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Managing Consultant
I wrote this a number of years ago: https://www.essential.exchange/2012/05/04/processing-large-and-embedded-groups-in-powershell/

I could probably write it to run much faster these days, but it works, so I still use it. :-)

If I understand what you want, you would need to add your changes around the line where it says "continue duplicate group".

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial