2009-07-29 65 views
6

假設你已經使用simiple語法連接到Active Directory:如何清除Active Directory中的用戶對象屬性?

string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com"; 
DirectoryEntry userEntry = Settings.GetADEntry(adPath); 

現在你想查看該用戶的屬性,比如郵件屬性:

Console.WriteLine("User's mail attribute is " + userEntry.Properties["mail"]); 

現在我該怎麼刪除郵件屬性值?

回答

13

它原來是非常簡單的,儘管不是很常用的...

string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com";DirectoryEntry userEntry = Settings.GetADEntry(adPath); 
userentry.Properties["mail"].Clear(); 
userentry.CommitChanges(); 
+0

完美解決,而無需使用調用與方法名。乾杯! – jamesbar2 2012-08-30 22:23:47

0

不知道,你可以刪除它,因爲用戶對象通常遵循公司的模式,但也可能像下面的工作:

userEntry.Properties["mail"] = null; 

或可能:

userEntry.Invoke("Put", "mail", null); 

則:

userEntry.CommitChanges(); 
相關問題