locked
How to retrieve groups for a user filtered by a specific OU in the Distinguised Name? RRS feed

  • Question

  • I have the following code to retrieve the groups a member directly belongs to (no recursion). I want to only return those groups that have "OU=GX GRP" and "OU=GRP" in the Distinguised Name without using a .Contains(), is there a way to do this using a specific "Context" as a parameter for GetGroups?

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using System.DirectoryServices.AccountManagement;  
     
    namespace GetRolesForUserSpike  
    {  
        class Program  
        {  
            static void Main(string[] args)  
            {  
                using (var context = new PrincipalContext(ContextType.Domain, null))  
                {  
                    using (var principal = UserPrincipal.Current)  
                    {  
                        using (var groups = principal.GetGroups())  
                        {  
                            foreach (var group in groups)  
                            {  
                                Console.WriteLine(group.Name);  
                                group.Dispose();  
                            }  
                        }  
                    }  
                }  
                Console.ReadKey();  
            }  
        }  

     


    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him a lifetime
    Monday, January 26, 2009 10:59 AM

All replies

  • Did you found a solution for that which you can share?
    kind regards, roni [http://netrsc.blogspot.com/]
    Thursday, January 14, 2010 12:14 AM
  • I can't remember, I am sorry about that. I no longer work for this customer and therefore I cannot verify.
    Give a man a fish and you feed him for a day. Teach a man to fish and you feed him a lifetime
    Thursday, January 14, 2010 10:13 AM