I need to write a C # script that returns all Active Directory groups with group names that start with a specific name. I know that I can return one group using the following code.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain); GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Groupname");
However, I need all the groups starting with the name Groupname, for example, "GroupPrefix". Then I want to go through all these groups using the following code and save the “members” in an array / list, which I can use later for searching.
foreach (UserPrincipal p in grp.GetMembers(true))
I would really appreciate any help I can get with this.
source share