Bulk Unenroll Students from Moodle Courses
Simple tip from a task this afternoon. Helping a school set up all their course enrollments for next year, needed a fast way to remove all students from the current course set up.
There’s no way to do this through the web front end as far as we could see, but a quick look at the database and the Moodle docs about enrollments came up with a solution. By no means am I suggesting this is the recommended way to go about this, but it worked for us so documenting here. If you are unsure about poking a database directly I would avoid it, or attempt it on a test server first.
To unenroll all students from a moodle site:
- Take a backup of your database
- Really, take a backup of your database… How bad would it be if it went wrong?!
- Find the mdl_role table and look for the roleid of the student role (on ours it was 5)
- Now, go to the mdl_role_assignments table and delete the rows with this roleid (DELETE FROM mdl_role_assignments WHERE roleid=’the correct student role id‘;)