title: Find Active Directory groups where group name like
body: <p>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.</p>
  
  <pre><code>PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
  GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "Groupname");
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>foreach (UserPrincipal p in grp.GetMembers(true))
  </code></pre>
  
  <p>I would much appreciate any help that I can get with this.</p>