2013-12-19 55 views
0

我们有一个需要更新/替换proxyAddresses内容的c#脚本。 我相信我了解如何添加值的范围如下:替换proxyAddresses值

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-随时纠正在上面的代码中的任何错误。如果这看起来是正确的 - 我的理解是,AddRange将追加我的新值,而不是替换当前值。有人可以请描述我可以如何使用这些新值删除/替换proxyAddresses的现有内容..?提前致谢。

回答