首页 > 解决方案 > 修改后为 AD 注释属性添加值

问题描述

我正在尝试在将值添加到 Active Directory 属性之前对其进行修改注意“Ldap 表示是信息”这个想法是寻找 | 然后做一个返回线示例: USA|France|Algeria 它将是:USA France Algeria

这是我的代码:

//Initialize Notes/info in AD
if (!string.IsNullOrEmpty(attributeNameForInfo))
{
    string infoFromPerson = owner.GetAttributeValue(attributeNameForInfo).ToSafeNullableString();
    if (!string.IsNullOrEmpty(infoFromPerson))
    {
        string info = infoFromPerson.Replace("|", "\n");

        TdnfTrace.Current.TraceEvent(TraceEventType.Verbose, 112233,
            "Custom AD RET : generating info value for " +
             owner.Login + " info : " + info);
        if (parameters != null && parameters.Keys.Contains("info"))
        {
            parameters["info"] = info;
        }
        else if (parameters != null && !parameters.Keys.Contains("info"))
        {
            parameters.Add("info", info);
        }
    }
    else
        TdnfTrace.Current.TraceEvent(TraceEventType.Verbose, 112233,
            "Custom AD RET : info value is null for " +owner.Login );
}

但它没有按应有的方式工作。我仍然在 Active Directory 中获取信息,例如 USA FRANCE ALGERIA 它只去掉“|”

我在一些可以使用的论坛上看到Set-ADUser username -Replace @{info='New info for the notes field'}

你能帮忙吗?谢谢

标签: c#cactive-directory

解决方案


所以我通过在“\n”之前添加“\r”解决了我猜的问题

string info = infoFromPerson.Replace("|", "\r\n");


推荐阅读