Rather a lot of work to do when you can simply reset the whole course and change the self-enrolment key to avoid former students to enrol again or suspend self-enrolment and enrol only the students you want with uploadusers. Another trick would be to backup-and-restore the course without user-data and again change enrolment-key or uploadusers you want into the new course ready for next term.
In another thread we discussed also how to automate this.
Rosario