System.DirectoryServices vs system.directoryservices.accountmanagement

I have an array (propertyList) that contains the names of some Active Directory properties whose data I want to receive. Using the Ironpython library and .NET System.DirectoryServices I decide to search for loadable properties as follows:

for propertyActDir in propertyList: obj.PropertiesToLoad.Add(propertyActDir) res = obj.FindAll() myDict = {} for sr in res: for prop in propertyList: myDict[prop] = getField(prop,sr.Properties[prop][0]) 

The getField function is mine. How can I solve the same situation using the system.directoryservices.accountmanagement library? I think that this is impossible.

Thanks.

+3
source share
2 answers

Yes, you're right - System.DirectoryServices.AccountManagement is based on System.DirectoryServices and was introduced with .NET 3.5. This simplifies the common tasks of Active Directory. If you need any special properties, you need to return to System.DirectoryServices.

See this C # code example for usage:

 // Connect to the current domain using the credentials of the executing user: PrincipalContext currentDomain = new PrincipalContext(ContextType.Domain); // Search the entire domain for users with non-expiring passwords: UserPrincipal userQuery = new UserPrincipal(currentDomain); userQuery.PasswordNeverExpires = true; PrincipalSearcher searchForUser = new PrincipalSearcher(userQuery); foreach (UserPrincipal foundUser in searchForUser.FindAll()) { Console.WriteLine("DistinguishedName: " + foundUser.DistinguishedName); // To get the countryCode-attribute you need to get the underlying DirectoryEntry-object: DirectoryEntry foundUserDE = (DirectoryEntry)foundUser.GetUnderlyingObject(); Console.WriteLine("Country Code: " + foundUserDE.Properties["countryCode"].Value); } 
+6
source

System.DirectoryServices.AccountManagement (excellent MSDN article on it here ) is designed to facilitate the management of users and groups, for example

  • Find users and groups.
  • create users and groups
  • Set specific properties for users and groups.

This is not intended to handle "general" property management, as you described - in this case, just keep using System.DirectoryServices , nothing bothers you!

Mark

+2
source

All Articles