We had a problem with massive amounts of test data being in our production environment. So I developed a little plugin that looks for certain strings in a username and purges that user - it goes through every table to make sure all references to that userid is also purged. It needs to be run from the command line and it requires a restore database (backup of your live data) in order to run. It dumps all the userids/usernames it is purging in a log file and there is a search utility that will go through the logs and return the userids/usernames. There is also a restore function that will take the data from the backup and put it back into the live database. Since this deals with permanently deleting users from a database it is very important to backup your data and to never run it for the first time in a production environment.
Since this is my first post, I can't link to it but you can find it on github at meganlkm/moodle-db-cleanup