2012-08-28 167 views
2

我正在尝试向Active Directory中的用户条目添加属性/属性。使用以下代码更新属性值时没有任何问题。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(); 

我有一个感觉我缺少一些简单的东西,但我似乎无法弄清楚。

+3

在Active Directory中定义了新属性吗?你扩展了AD模式吗?你不能在AD中设置任意的新属性...... –

回答

0

我不明白,通常一个属性/属性不会出现,除非它填充了一个值。正如marc_s所暗示的属性已经存在于模式中,您只需使用值填充它。

相关问题