I need to write a C# script that returns all the Active Directory groups with group names that start with a certain name. I know can return one group using the following code.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Groupname");
However, I want all the groups where the Groupname starts with, say "GroupPrefix". I then want to traverse all these groups using the following code and store the "members" in an array/list that I can use later for searching.
foreach (UserPrincipal p in grp.GetMembers(true))
I would much appreciate any help that I can get with this.