Frage

We have a c# script that needs to update/replace the proxyAddresses contents. I believe I understand how to add a range of values as follows:

DirectoryEntry entry = new DirectoryEntry(myConnectString);
DirectorySearcher Dsearch = new DirectorySearcher(entry);
Dsearch.Filter = "(sAMAccountName=" + theUser + ")";
SearchResult result = Dsearch.FindOne();
if (result != null)
{
 if (result.Properties.Contains("proxyAddresses"))
 {
   DirectoryEntry Uentry = result.GetDirectoryEntry();
   Uentry.Properties[proxyAddresses].AddRange(new object[] {"user1@domain.com", "user2@domain.com"});
   Uentry.CommitChanges();
 }
}

However- feel free to correct any errors in the above code. If this looks correct - my understanding is that AddRange will append my new values rather than replacing the current values. Can someone please describe how I can remove/replace the existing contents of proxyAddresses with these new values..? Thanks in advance.

War es hilfreich?

Lösung

This will replace the proxyAddresses properties

Uentry.Properties["proxyAddresses"].value = new object[] {"user1@domain.com", "user2@domain.com"};

There are more examples about how to work with proxyAddresses here

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top