Set Property Method to assign value to AD Attributes/Properties

public static void SetProperty(DirectoryEntry oDE, string PropertyName, string PropertyValue)
{
    if ((PropertyValue != string.Empty) && (PropertyValue != null))
    {
        if (oDE.Properties.Contains(PropertyName))
        {
            oDE.Properties[PropertyName][0] = PropertyValue;
        }
        else
        {
            oDE.Properties[PropertyName].Add(PropertyValue);
        }
    }
    else
    {
        if (oDE.Properties.Contains(PropertyName))
        {
            oDE.Properties[PropertyName].Clear();
        }
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s