我们有一个 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[] {"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9aefe9ffe8abdafef5f7fbf3f4b4f9f5f7" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a7f796f78384a6e65676b636424696567" rel="noreferrer noopener nofollow">[email protected]</a>"});
Uentry.CommitChanges();
}
}
但是,请随意更正上述代码中的任何错误。如果这看起来正确 - 我的理解是 AddRange 将附加我的新值而不是替换当前值。有人可以描述一下如何用这些新值删除/替换 proxyAddresses 的现有内容吗?提前致谢。
最佳答案
这将替换 proxyAddresses
属性
Uentry.Properties["proxyAddresses"].value = new object[] {"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bfef8eef9bacbefe4e6eae2e5a5e8e4e6" rel="noreferrer noopener nofollow">[email protected]</a>", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8bfef8eef9b9cbefe4e6eae2e5a5e8e4e6" rel="noreferrer noopener nofollow">[email protected]</a>"};
关于c# - 替换 proxyAddresses 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20692767/