Can I suggest that you use external database
enrollment as a method of enrolling your users, there is a how to guide in the administrators documentation here on moodle.org, (config in moodle is administration>>enrollment>>external database enrollment) use it for over 2000 users and it works great. basically how it works is like this. in your Moodle database there is a table called mdl_course, once you have this table populated all courses will have a shortcode. in the external database you have 3 columns one for username one for course and one for role. when the user logs ij the external database in consulted to see which course the user is enrolled in and what kind of access they have (based on their role) so
when user1 logs in and your external database has
user1 courseshortcode1 student
user1 courseshortcode2 student
then user1 will be enrolled in whatever courseshortcode1 & 2 happen to be.
I am assumming that your number one issue is that you need users enrolled in courses before they log in rather than putting users into moodle groups as you will still have to enroll those groups.
hope that helps.