Reputation: 71
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[] {"[email protected]", "[email protected]"});
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.
Upvotes: 2
Views: 4322
Reputation: 10844
This will replace the proxyAddresses
properties
Uentry.Properties["proxyAddresses"].value = new object[] {"[email protected]", "[email protected]"};
There are more examples about how to work with proxyAddresses here
Upvotes: 3