简体   繁体   中英

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?

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. 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. 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.

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?

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() .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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