Our organization uses groups to share courses among multiple sites. However, we wanted an easy way to create and maintain identical groups in multiple classes, so this script was created.
In our setup we wanted group names and settings, as well as group members (the teachers) to be identical in all courses where we were using groups. Our students enroll in courses and are assigned to the appropriate group by using the group password.
The script is a cron addition that first looks for courses with Group Mode set to "Separate Groups" and modifies these courses to have the same group settings as the Template Course (including removing any groups not found in the Template Course).
The script does NOT remove any users from existing groups, but does add them. This prevents our students from being removed from groups, since they're actually entered into groups on a course-by-course basis, rather than a site-wide basis.
Because the script can delete groups, please backup before running.
Installation is simple, though. Just define the Template Course's ID on line 4 of cron.php and place the file at [site root]/local/cron.php (you may have to create the "local" directory). Each course with groupmode = 1 (Group Mode = Separate Groups) will have the groups modified to match the Template Course's groups the next time your cron job runs.
I wrote this for Moodle 1.9 and haven't tested it in anything prior.
If you have any questions, please email me.