In accordance with "Managing Directory Security Principles in the .NET Framework 3.5," specializing in the architecture below and System.DirectoryServices.AccountManagement Namespace article, accountManagement is intended for groups of users and computers (security principals).
For organizationalUnit
you can use System.DirectoryServices.ActiveDirectory
, here is an example:
using System.DirectoryServices; ... DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/ou=Monou,dc=dom,dc=fr", "jpb", "PWD"); DirectorySearcher ouSrc = new DirectorySearcher(deBase); ouSrc.Filter = "(OU=TheNewOU)"; ouSrc.SearchScope = SearchScope.Subtree; SearchResult srOU = ouSrc.FindOne(); if (srOU == null) { DirectoryEntry anOU = deBase.Children.Add("OU=TheNewOU", "organizationalUnit"); anOU.Properties["description"].Value = "The description you want"; anOU.CommitChanges(); }
Remember to use the using(){}
directive
source share