Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created March 10, 2017 01:38
Show Gist options
  • Save adamdriscoll/d59af1e6e0f89973b868c2b64f100e77 to your computer and use it in GitHub Desktop.
Save adamdriscoll/d59af1e6e0f89973b868c2b64f100e77 to your computer and use it in GitHub Desktop.
Set attribute LDAP
var connectionObject = new LdapConnection(new LdapDirectoryIdentifier(controller), new NetworkCredential(username, password));
var directoryAttributeModification = new DirectoryAttributeModification();
directoryAttributeModification.Name = attribute;
directoryAttributeModification.Operation = DirectoryAttributeOperation.Replace;
foreach (var value in values)
{
if (value is byte[])
{
directoryAttributeModification.Add(value as byte[]);
}
else
{
directoryAttributeModification.Add(value.ToString());
}
}
var response = connectionObject.SendRequest(new ModifyRequest
{
DistinguishedName = dn,
Modifications =
{
directoryAttributeModification
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment