【问题标题】:Replacing proxyAddresses values替换 proxyAddresses 值
【发布时间】:2014-01-08 16:12:00
【问题描述】:

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

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();
 }
}

但是,请随时更正上述代码中的任何错误。如果这看起来正确 - 我的理解是 AddRange 将附加我的新值而不是替换当前值。有人可以描述我如何用这些新值删除/替换 proxyAddresses 的现有内容..?提前致谢。

【问题讨论】:

    标签: c# active-directory multiple-value


    【解决方案1】:

    这将替换 proxyAddresses 属性

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

    还有更多examples about how to work with proxyAddresses here

    【讨论】:

    • 这会替换proxyAddresses的现有内容还是只是追加到它上面?
    • @dev 它将替换它
    • 代码错误,有人拒绝了我的编辑。您需要在属性名称周围加上引号。
    • 应该是 Uentry.Properties["proxyAddresses"].Value = ....
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    相关资源
    最近更新 更多