AnsweredAssumed Answered

Batch deleting users based on a role

Question asked by richardstokesesriaustralia-com-au-esridist Employee on Sep 5, 2017
Latest reply on Oct 31, 2017 by MKellyesri-ireland-ie-esridist



I'm trying to convert an old portalpy/excalibur script that 'wipes' an ArcGIS Online organisation based on a role, but I'm struggling to recreate it in Python API.  Every week or so my current script seems to fail or present a new error, so I figure now is the time to update it.


The steps the script takes are as follows:


  1. Sign in as an administrator for the organisation
  2. Get a list of all users who have a particular role
  3. Remove any licenses that the users have assigned
  4. Remove any delete-protection on items
  5. Delete any content (including folders, and then groups)
  6. Delete the users
  7. Recreate the users (based on a csv list)
  8. Re-invite the user to predetermined groups


I've been using notebooks so far as it fits my limited knowledge of code and allows me to see where things are going wrong.  Trouble is, it's going wrong everywhere!


I can get a list of users, and then find and delete their content, but I can't seem to work out how to delete their folders and any groups that they're a member of.  It's possibly a very simple answer, but I figure I may as well ask in case it's also useful for anyone else.


Does anyone have an example script (using the Python API) or any tips to fully deleting users?