A previous post of mine that covered LDAP searches in non-Microsoft Active Directory LDAP directories (ex. OpenLDAP, Oracle Internet Directory, Novell eDirectory, etc.) gained a fair amount of popularity and I received requests to follow up on it to provide instructions on performing other LDAP functions using the .Net Framework and PowerShell.
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 add another inetorgperson object to the testou1 OU. 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 AddRequest object and receive an AddReply.
The sample code below is designed to demonstrate how to create an LDAP entry, in practice this might be designed to use the command, content enricher, and decorator patterns 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.