How do I bulk delete users?

radioactivelamb
Kilo Contributor

We are using a test/sandbox instance and are very new to the platform. We have imported a large number of users, but now need to remove some of them. Please describe how I can bulk delete users based on the domain name of their email address (or other criteria if it is simple). We're looking to delete about 6500 users.

 

Thank you

1 ACCEPTED SOLUTION

Bhavesh Jain1
Giga Guru

var user = new GlideRecord('sys_user');


user.addQuery('email','CONTAINS','enter_your domain');


user.setLimit('7000'); // Set limit so the query does not delete more users


user.query();


gs.log('Number of users to be deleted-->'+user.getRowCount());


while(user.next())


{


user.deleteRecord();


}




Check the above log before you actually delete the users to confirm if the query is working fine. Run the above script in background script.


Hope it helps.


View solution in original post

7 REPLIES 7

Hi Andrew,



my experience is that setLimit will be ignored by deleteMultiple. For your example it means all user which match the query will be deleted and not only the first 7.000.



Best regards


Dirk


Subhajit1
Giga Guru

Just to add to what Bhavesh said, you can also put in a identifier in the log for filtering purposes on the message.


Also it is suggested that do not delete 6500 records at one go as it might cause performance issues.


radioactivelamb
Kilo Contributor

This worked great. Thank you.