Continuing from my last post, I went ahead and set up an OpenLDAP server for demonstration purposes utilizing the core, cosine, and inetorgperson schemas. I have prepopulated it with the following objects:
o: Mikes Technology Blog
description: My first test OU
description: My second test OU
In this example, we will modify the testuser user in testou1 to be contained in a new container (ou=testou2,dc=mikesblog,dc=lan). Optionally, we can also rename the user (I show the field below, but don't actually rename the user).
To accomplish this, we will use the .Net framework classes in the System.DirectoryServices.Protocols namespace. The LdapConnection class gives our application connectivity to the LDAP server where we can provide an ModifyRequest object and receive an ModifyReply. In the ModifyRequest, we specify via the Modifications property what attribute additions, modifcations, and deletions need to occur.
The sample code below is designed to demonstrate how to modify attributes for an LDAP entry, in practice this might be designed to use the command pattern, content enricher pattern, and decorator pattern instead of the hardcoded transaction script below.
Let's get to it... The sample C#.Net code:
Not to disappoint, below is the PowerShell port of the above code.