Personally, I would script it using Moodle web services or even Moosh (https://moosh-online.com/).
General help
Add and suspend user account from external database
This discussion has been locked so you can no longer reply to it.