gpt4 book ai didi

c# - Active Directory 添加用户属性

转载 作者:太空宇宙 更新时间:2023-11-03 16:27:19 25 4
gpt4 key购买 nike

我正在尝试将特性/属性添加到 Active Directory 中的用户条目。使用以下代码更新属性值没有任何问题。

string LDAPString = "LDAP://DC=oc,DC=edu";
DirectoryEntry ou = new DirectoryEntry(LDAPString, "fakeUsername", "password");

DirectorySearcher searcher = new DirectorySearcher(ou);
searcher.Filter = "sAMAccountName=" + username;
SearchResult result = searcher.FindOne();

DirectoryEntry user = new DirectoryEntry(result.Path, "fakeUsername", "password");

user.Properties[propertyName].Value = propertyValue;

user.CommitChanges();

user.Dispose();

但是,当我尝试添加新项目并调用 CommitChanges() 时,它会抛出一个错误:

The specified directory service attribute or value does not exist.

ExtendedErrorMessage 表示以下内容:

00000057: LdapErr: DSID-0C090B8A, comment: Error in attribute conversion operation, data 0, v1db1

string propertyName = "test";
string propertyValue = "testValue";
user.Properties[propertyName].Add(propertyValue);
user.CommitChanges();

我觉得我错过了一些简单的东西,但我似乎无法弄明白。

最佳答案

我不明白通常一个属性/属性不会出现,除非它被填充了一个值。由于 marc_s 提到的属性已经存在于模式中,您只需用一个值填充它即可。

关于c# - Active Directory 添加用户属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12163273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com