I’m writing a small application which updates my AD with info from a DB table, but are having trouble finding examples of best practices.
As far as I understand, I’ll need to:
- create a
DirectorySearcherwith a filterobjectClass=userand search for the given cn - if found, I need to use
result.getDirectoryEntryto get a handle to the actual object, - Update all the values to my
entryobjectwith the one’s from the db and then commit changes
Is that it or am I totally lost, any hints or examples are welcome
If you’re on .NET 3.5 and up, you should check out the
System.DirectoryServices.AccountManagement(S.DS.AM) namespace. Read all about it here:Basically, you can define a domain context and easily find users and/or groups in AD:
The new S.DS.AM makes it really easy to play around with users and groups in AD!
If you need to search a whole bunch of users, you can use a
PrincipalSearcherand a “query-by-example” principal to do your searching:You can specify any of the properties on the
UserPrincipaland use those as “query-by-example” for yourPrincipalSearcher.