According to Managing Directory Security Principals in the .NET Framework 3.5 specialy the architecture here under and System.DirectoryServices.AccountManagement Namespace article, accountManagement is for users groups and computers (security principals).
For organizationalUnit
, you can use System.DirectoryServices.ActiveDirectory
here is an example :
using System.DirectoryServices;
...
/* Connection to Active Directory
*/
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)
{
/* OU Creation
*/
DirectoryEntry anOU = deBase.Children.Add("OU=TheNewOU", "organizationalUnit");
anOU.Properties["description"].Value = "The description you want";
anOU.CommitChanges();
}
Don't forget to use using(){}
directive
PrincipalContext
to retreive theContainer
value. – Hammer