In my place we were badly needing a synchronisation of existing LDAP groups with the new Moodle 2.0 cohorts.
Please find enclosed a little piece of code that just do it as a CLI script to be run nightly after the synching of Moodle's users with a LDAP/CAS directory
It does the job in my place with LDAP groups registered as groupOfUniqueNames and member attribute as uniquemember
It deserve some improvments such as internationalization and two extra global configuration settings for places were my values are not used
Currently they are 'hardcoded' in my class constructor
$this->config->group_attribute = 'cn';
$this->config->group_class = 'groupOfUniqueNames';
Provisions are made for specific retrieving of group members against Active Directory where the number of members is greater than 999
where MS do not use the standard response but returns results by pages of 1000 ... see http://msdn.microsoft.com/en-us/library/aa367017%28VS.85%29.aspx
(untested here since we do not have anymore MS AD around)
If it can find its way in Moodle 2.0 core ...