简体   繁体   English

删除 DirectoryEntry 中的某些属性(Active Directory、C#)

[英]Removing certain properties in DirectoryEntry (Active Directory, C#)

This is similar to the question/answers raised in this link: How do I clear out a user object attribute in Active Directory?这类似于此链接中提出的问题/答案: 如何清除 Active Directory 中的用户对象属性?

For the most part Clear() seems to work and that's what I'm getting in most of my googl-ing but it doesn't for certain properties: in my (C#) code, I was unable to remove the property 'mobile' (number) for a user.在大多数情况下,Clear() 似乎有效,这就是我在大部分谷歌搜索中得到的结果,但它不适用于某些属性:在我的 (C#) 代码中,我无法删除属性“移动” (数字)为用户。 Every time I cleared the entry and saved, the save would not take effect and the value remains the same.每次我清除条目并保存时,保存都不会生效并且值保持不变。

When I attempted to do so directly in ADUC it succeeded, but only by removing the entire 'mobile' property.当我试图直接在 ADUC 中这样做时,它成功了,但只是通过删除整个“移动”属性。 I've no problems with that, but attempting to do so in code turns up nothing - the DirectoryEntry.PropertyCollection property where I got the values from had no methods to remove a property directly.我对此没有任何问题,但是尝试在代码中这样做没有任何结果 - 我从中获取值的 DirectoryEntry.PropertyCollection 属性没有直接删除属性的方法。

I looked up the PropertyCollection documentation and found that the Remove method is private so that explains it, but then what is the equivalent alternative that I can try?我查看了PropertyCollection文档,发现 Remove 方法是私有的,因此可以解释它,但是我可以尝试的等效替代方法是什么?

For what it's worth (6 years and a pandemic later) I think I found a workaround for this: I used the System.DirectoryServices.AccountManagement.PrincipalContext class from the Account Management framework to save my changes to and applied them rather painlessly by calling .Save() .对于它的价值(6 年和之后的大流行),我想我找到了一个解决方法:我使用了帐户管理框架中的System.DirectoryServices.AccountManagement.PrincipalContext类来保存我的更改并通过调用.Save()

This brings in its own bag of problems and complications but for the most part combining aspects of both frameworks managed to cover all the AD requirements I had.这带来了它自己的问题和复杂性,但在大多数情况下,结合两个框架的各个方面设法涵盖了我拥有的所有 AD 要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM