29 July 2019

How do I aggregate multiple OUs with the Active Directory Connector

If I have multiple OUs in my Active Directory, how can I combine them into one data set.

Answer


The Active Directory connector can access 1 OU at a time as you need to specify the OU on the connection path.

If you want to read multiple OUs then you can override the Data Load with Dynamic Columns and call the underlying load multiple times. This is slightly tricky with data connectors that use identifier columns but can be done like the example below.

Within Dynamic Columns add this method below to override the Data Load and call it twice with different OU Path. This has the effect of combining the 2 data sets. Note that this will only work if your reading from AD i.e. AD is your source.

 public override DataTableStore GetDataTable(DataTableStore dt, IDataSourceReader reader) 
    {
        var myreader = GetDataSourceA();
    
        myreader.LDAPPath = "LDAP://OU=TestUsers,DC=internal,DC=simego,DC=com";    
        dt = myreader.GetDataTable(dt);
        
        myreader.LDAPPath = "LDAP://OU=CRM2016,DC=internal,DC=simego,DC=com";    
        
        foreach(DataTableStoreRow row in reader.GetDataTable(reader.SchemaMap.GetDataTable()).Rows)
        {
            dt.Rows.AddWithIdentifier(row, row.ItemIdentifierData);
        }
            
        return dt;                    
    }

Here is an alternative answer where we use an array of OUs and loop round them the first one needs to called slightly differently after that you can easily loop the others.

public override DataTableStore GetDataTable(DataTableStore dt, IDataSourceReader reader) 
{
	var myreader = GetDataSourceA();

	myreader.LDAPPath = "LDAP://OU=TestUsers,DC=internal,DC=simego,DC=com";	
	dt = myreader.GetDataTable(dt);
	
	var myOUs = new [] { 
		"LDAP://OU=CRM2016,DC=internal,DC=simego,DC=com", 
		"LDAP://OU=CRM2015,DC=internal,DC=simego,DC=com"
	};
	
	foreach(var ou in myOUs)
	{
		 myreader.LDAPPath = ou;    
    
        foreach(DataTableStoreRow row in reader.GetDataTable(reader.SchemaMap.GetDataTable()).Rows)
        {
            dt.Rows.AddWithIdentifier(row, row.ItemIdentifierData);
        }	
	}
	
	return dt;
				
}