Export Active Directory User Group Membership

11 December 2014

In this example we show how you can use Data Sync to create a Data Set from your Active Directory that returns all the Groups that your users belong to.

The idea is that we want a rows for each user and group like this below.

Data

By default Data Sync will return the Group membership (Member Of) as a Comma separated List Like this Builtin,Remote Desktop Users,Simego Remote Desktop Users,Users

We need to use a little Trick in Dynamic Columns to override the Row loading and expand this list into multiple rows for each group copying the values across the rows.

Go into Dynamic Columns and use the code below to expand the Member Of column into multiple rows.

using System;

partial class DataSourceRowOverride : Simego.DataSync.DynamicColumns.DataSourceRowInternal //Do Not Change This Line
{
    public override bool BeginRow()
    {        
        if(!string.IsNullOrEmpty(MemberOf))
        {
            var parts = MemberOf.Split(',');
            
            if ( parts.Length > 1 )
            {
                foreach(var s in parts)
                {
                    var new_row = Table.NewRow();
                    foreach(var c in Table.Columns) 
                    {
                        if ( c.ColumnName == "Member Of" )
                        {
                            new_row[c.ColumnName] = s;
                        } 
                        else 
                        {
                            new_row[c.ColumnName] = Row[c.ColumnName];    
                        }
                    }
                    
                    Table.Rows.AddWithIdentifier(new_row, ADPath);
                }
                
                return false;
            }
        }
                            
        return true; 
    }    
}

Since the DSID is no longer unique we need to use a combination of 2 columns for the Key we are using DSID and Member Of.

Schema Map

Now when you look at the results you get Rows for each Group and User.

Preview A

| |