I have a process that I need to grab members from a specific security group and for each member, I need to extract out any groups that meet a specific RegEx. In this case it is any 4-digit security groups. I have this working, but it is extremely slow, hours to run. The target group has 6000+ users in it.
My script currently gets all the members of the group, stores in a variable. Next, I have a foreach loop that uses Get-ADPrincipalGroupMembership and Where-Object to grab any security groups with my RegEx string. I grab that along with some other properties and put into a PSCustomObject. Then all is dumped to a CSV and appended.
Is there a faster way to accomplish this?