When getting values Active Directory in C#, my normal process is to use the principal context to get most of these values. There are still some things I need LDAP to get because they aren't available from a user principal object. For these attributes, I use the underlying object to get access to a directory entry. I made a method to check for the existence of an property by checking if it is null. If it isn't null, I return the value as a string. I use code similar to what is listed below to accomplish this:
if (directoryEntrygroup.Properties[directoryEntryPropertyName].Value != null)
{
returnValue = directoryEntrygroup.Properties[directoryEntryPropertyName].Value.ToString();
}
That works pretty well for attributes that do not contain a list of values, such as a "cn" or "department." But for attributes such as "ManagedObjects" that do have some type of collection but returned as a object, what is the best way to get those values? For what its worth, this code is within a script task in SSIS for SQL Server 2012 using Framework 4.0.