public static void SetProperty(DirectoryEntry oDE, string PropertyName, string PropertyValue) { //check if the value is valid, otherwise dont update if(PropertyValue !=string.Empty) { //check if the property exists before adding it to the list if(oDE.Properties.Contains(PropertyName)) { oDE.Properties[PropertyName][0]=PropertyValue; } else { oDE.Properties[PropertyName].Add(PropertyValue); } } }