1

When I received this Drupal 7 site to manage, it has had years of being open for people to make accounts and now I have ~ 300 PAGES of users with names like ismehacker1234568 and such, with under a dozen legitimate accounts I need to keep.

Once, on another site long ago I tried removing the users from the database table using a SQL query. That was a disaster and broke the entire site. I want to avoid that this time around.

I also need to delete any content they made, but not anything the legitimate users made.

4
  • 1
    Use views bulk operations to make short work of this.
    – Kevin
    Jan 11 at 16:19
  • 4
    Does this answer your question? How to delete 'blocked' users in bulk?
    – mbomb007
    Jan 11 at 20:04
  • @mbomb007 I don't think that answers the question because they also want to delete the content created by the blocked users.
    – Matt
    Feb 9 at 21:48
  • @Matt One of the options when canceling user accounts is to delete the content as well. See my answer below.
    – mbomb007
    Feb 12 at 19:28
1

As stated in the comments, Views Bulk Operations provides helpful functionality. You can use the "select all" checkbox on the /admin/people page to select all the users, then deselect the few you want to keep. From the dropdown, you can then choose "Cancel user account". After submitting, you will select the method by which to cancel the accounts in bulk (such as Delete the account and its content, or Delete the account and make its content belong to Anonymous).

0

My suggestion is to prepare a text file with 1 username per line and use Drush in a shell script (assuming Drush 8), do this:

IFS="
"
for user in `cat users.txt`
do
echo "Cancelling user: $user"
drush -y user-cancel --delete-content ${user}
done

This way you will loop over your file and delete one user at a time.

Another approach is to massive delete all of them using a comma-separated approach:

drush -y user-cancel --delete-content `cat users.txt | paste -d ',' -`
2
  • Does this also delete the content the users created? The question says "I also need to delete any content they made"
    – mbomb007
    Feb 12 at 19:26
  • Oops, sorry, I forgot a parameter. I've edited my answer and it does now.
    – jbarrio
    Feb 15 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.