Creating OU Hierarchy from DN ?

M

markarichman

Is there an easy way to create an OU hierarchy, given a DN?

For example, I have a DN like:
"OU=123456,OU=32,OU=54,OU=6,OU=Customers,OU=x,OU=y,OU=z"
where the "OU=Customers,OU=x,OU=y,OU=z" part already exists.

Can I just create "OU=123456,OU=32,OU=54,OU=6" under "OU=Customers"
easily?

I'm using C#, but any example would be helpful.

Thanks,
Mark
 
M

Marc Scheuner [MVP ADSI]

For example, I have a DN like:
"OU=123456,OU=32,OU=54,OU=6,OU=Customers,OU=x,OU=y,OU=z"
where the "OU=Customers,OU=x,OU=y,OU=z" part already exists.

Can I just create "OU=123456,OU=32,OU=54,OU=6" under "OU=Customers"
easily?

No, you can't do that - you'd need to add each level separately, e.g.

* create OU=6 under OU=Customers
* then create OU=54 under the newly created OU=6
* then create OU=32 under the newly created OU=54

and so forth.

You'd do this something like that:

// bind to the last existing OU - you need the FULL, complete
// LDAP, which ought to include a domain component
// (the dc= parts)
DirectoryEntry deOU = new
DirectoryEntry("LDAP://OU=Customers,OU=x,OU=y,OU=z,dc=yourcompany,dc=com");

// create a new OU
DirectoryEntry deNewOU = deOU.Children.Add("ou=6",
"organizationalUnit");

// possibly set any other attributes you need to set on this OU
deNewOU.Properties["...."].Value = ...... ;

// go on to the next level, create the next OU below that
DirectoryEntry deNewOU2 = deNewOU.Children.Add("ou=54",
"organizationalUnit");

// possibly set any other attributes you need to set on this OU #2
deNewOU2.Properties["...."].Value = ...... ;

// go on to the next level, create the next OU below that
DirectoryEntry deNewOU3 = deNewOU2.Children.Add("ou=32",
"organizationalUnit");

and so forth

HTH

Marc
________________________________________________________________
Marc Scheuner ** mscheuner -at- mvps.org ** http://adsi.mvps.org
Microsoft MVP for Directory Services Programming
http://www.dirteam.com/blogs/mscheuner/default.aspx
http://groups.yahoo.com/group/ADSIANDDirectoryServices/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top