Thursday, June 3, 2010

Deleting Google Apps User Accounts

Edit: As of April 20, 2015 Google has deprecated this API and this script will no longer work. For scripts that will work, check out:
https://github.com/misterhay/GoogleAppsProvisioning
or
https://github.com/jay0lee/GAM/tree/master.


Coming up to the end of a school year you may find yourself needing to bulk delete the Google Apps user accounts for your school (or district) domain for students that are moving on from your school. That is, if your district hasn't implemented automatic provisioning.


I've written a little script to help automate this process, everything you need is included in this zip file.


To bulk delete users from your domain:
  1. Enable the Provisioning API for your Google Apps domain (log in with your admin account at http://google.com/a/yourdomain , click the Users and groups tab, then the Settings subtab, select the checkbox to enable the Provisioning API, and save your changes).
  2. Unzip the his file that you downloaded by right clicking the downloaded file and choosing Extract All...
  3. Edit the text file named deleteaccounts.txt so that it contains each unwanted user account on its own line. You can likely get information for this from your student information system.
  4. Run the program GoogleAppsDeleteUsers.exe .
  5. The program will ask you for your Google Apps domain, administrator account, and password. Don't worry, it doesn't write these to a file or email them to anyone.
  6. Watch as the user accounts are slowly deleted one by one without you having to do anything else.


Since you shouldn't just run programs downloaded from people you don't trust, I've also made the source code available. It's written in Python 2.6, depends on the Google Data Python Library, and compiled for Windows with py2exe. Feel free to improve on it or reuse it. This is my first foray into Python, and I am indebted to jay0lee for some of the ideas in his Google Apps Manager.


Edit: Before deleting users, you may want to direct them to our post on Downloading Your Google Sites.

Edit: You can also check out a web-based version that I put together.

13 comments:

  1. Hi.
    Shis is not working right for me.. please help I can login but it will not del...dcollins@myases.org

    ReplyDelete
  2. This looks to be a fantastic tool, but i have hit on a problem, it accepts my credentials as admin, starts to delete the first account but no matter how i list the username (1234 or 1234@mydomain.com)it reports that it is first 'Deleting user account: 1234'
    then:
    '0 user accounts have been deleted, but there was an error.'
    Any ideas?

    ReplyDelete
  3. Unfortunately because this makes use of the provisioning API it is "only available to Google Apps for Business, Education, and ISPs customers"

    http://code.google.com/googleapps/domain/gdata_provisioning_api_v2.0_reference.html

    ReplyDelete
  4. We're running GApps for Edu and I can't get this script to delete accounts either.
    I've tried both username per line and also full username with email address per line in the text file. Nada.

    Any ideas?

    ReplyDelete
  5. I'm assuming that you've checked the box to enable the Provisioning API.
    https://developers.google.com/google-apps/provisioning/#enabling_the_provisioning_api

    When I get a chance this week or next I'll try it out on one of our domains to see if the script is still working for me. I may also see if I can write in some better error reporting so we can see why the script fails.

    ReplyDelete
  6. This is the second year I have used this excellent tool to help me delete the 200+ graduates who have left our school.

    Thank you so much for this tool which makes my work so much easier at the end of each school year. I have never really mastered getting GAM to do a loop through a csv list to bulk delete a group of users, but your program makes it easy and works like a charm.

    ReplyDelete
  7. Excellent, thanks Ms. Martin for your kind words. You can also check out my web-based version (using Google Apps Script) that I blogged about at http://haytech.blogspot.ca/2013/06/google-apps-bulk-delete-users-script.html

    ReplyDelete
  8. Any idea why it stops after 20-30 user deletes? It did over 300 first time. Is there a character limit in name?

    I keep having to run the program. It is better than manually doing it. Thanks so much for sharing.

    ReplyDelete
  9. @mr_mahoney I'm not sure why it would stop, I didn't really write any error handling or messages. Feel free to check out the source code, of course.

    You can also try out the web-based version that I mentioned: http://haytech.blogspot.ca/2013/06/google-apps-bulk-delete-users-script.html

    ReplyDelete
  10. I always get 0 accounts have been deleted, but there was an error

    ReplyDelete
    Replies
    1. Unfortunately the API used by this script was depricated on April 20, 2015 so it will no longer work. For more updated scripts, check out https://github.com/misterhay/GoogleAppsProvisioning

      Delete
    2. I see the scripts which one do I need to delete the accounts & do you have any instructions? Any help would be appreciated. I have about 1200 kids to delete.

      Delete
    3. This might be easier than trying to sort through my examples. He has better documentation: https://github.com/jay0lee/GAM/wiki/BulkOperations

      Delete