« Back

Script to delete Liferay users

The following BeanShell script can be used to bulk delete all non-admin users in a Liferay instance, including their groups, subscriptions, announcements, assets, blogs, etc.:

import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.service.UserLocalServiceUtil;
import java.util.concurrent.*;

pool = Executors.newFixedThreadPool(20);

for (user : UserLocalServiceUtil.getUsers(0, 99999)) {
  if (user.isDefaultUser() || PortalUtil.isOmniadmin(user.getUserId())) {
    System.out.println("Skipping user " + user.getScreenName());
  } else {
    final Object userToDelete = user;
    pool.execute(new Runnable() {
        public void run() {
            System.out.println("Deleting user " + userToDelete.getScreenName());
            UserLocalServiceUtil.deleteUser(userToDelete);
        }
    });        
  }
}

 

Paste this script into Control Panel > Server Administration > Scripts, with the "BeanShell" selected as the language.

Check the logs for the progress and/or errors.

Note: Use with caution! This script cannot be rolled back.

 

 

Comments
Trackback URL:

No comments yet. Be the first.