Question : C# DirectoryServices application question

I am using C# and .NET 2005 DirectoryServices and I am attempting to add an AD user account to a particular OU and I can't seem to figure out how to get it to work.  I am able to add the user to a security group (DnsAdmins as an example) but I can't figure out how to add to a user created OU.  Also, it would be helpful to know how to navigate nested OU trees.  For example, we have several satelite offices that users are located at, so we have a Los Angeles OU and inside that OU, we have several OU's broken up by divsion, and then in those OU's we have either laptop or workstation OU's which is where the actual AD user objects reside.  I'm trying to figure out what is the best way to specify these nested OU's for the user to be placed in programmatically.  Any suggestions?

Answer : C# DirectoryServices application question

to get  list of all OU in AD:
1:
2:
3:
4:
5:
6:
7:
8:
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://<AD_SERVER>/dc=DOMAIN,dc=COM");
            DirectorySearcher dsFindOUs = new DirectorySearcher(rootEntry);
            dsFindOUs.Filter = "(objectClass=organizationalUnit)";
            dsFindOUs.SearchScope = SearchScope.Subtree;
            foreach (SearchResult result in dsFindOUs.FindAll())
            {
                Console.WriteLine(result.Path);
            }
Random Solutions  
 
programming4us programming4us